-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCUserDB.cpp
More file actions
90 lines (61 loc) · 1.54 KB
/
SCUserDB.cpp
File metadata and controls
90 lines (61 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "SCUserDB.h"
#include <cctype>
using std::string;
using std::map;
UserDatabase::users UserDatabase::m_users;
UserDatabase::iterator UserDatabase::find( Connection<Telnet>* p_connection )
{
iterator itr = m_users.begin();
while( itr != m_users.end() )
{
if( itr->connection == p_connection )
return itr;
++itr;
}
return itr;
}
bool UserDatabase::AddUser( Connection<Telnet>* p_connection, string p_name )
{
if( !HasUser( p_name ) && IsValidName( p_name ) )
{
m_users.push_back( User( p_connection, p_name ) );
return true;
}
return false;
}
void UserDatabase::DeleteUser( Connection<Telnet>* p_connection )
{
iterator itr = find( p_connection );
if( itr != m_users.end() )
m_users.erase( itr );
}
bool UserDatabase::HasUser( string& p_name )
{
iterator itr = m_users.begin();
while( itr != m_users.end() )
{
if( itr->name == p_name ) return true;
++itr;
}
return false;
}
bool UserDatabase::IsValidName( const string& p_name )
{
static string inv = " \"'~!@#$%^&*+/\\[]{}<>()=.,?;:";
// must not contain any invalid characters,排除无效字符的好方法!
if( p_name.find_first_of( inv ) != string::npos )
{
return false;
}
// must be less than 16 chars
if( p_name.size() > 16 || p_name.size() < 3 )
{
return false;
}
// must start with an alphabetical character
if( !isalpha( p_name[0] ) )
{
return false;
}
return true;
}