Stupid winsock needs special way to close sockets.
[dftpd.git] / AuthToken.cpp
blobbc250b072a2cd33c5b6622890e273f09c1617319
1 #include <stdlib.h>
2 #include <time.h>
3 #include "AuthToken.hpp"
4 #include "Log.hpp"
6 AuthToken::AuthToken()
7 : m_token( "" )
9 srand( time( NULL ) );
12 bool AuthToken::Login( const std::string& login )
14 return true;
17 bool AuthToken::Password( const std::string& login, const std::string& password )
19 if( !TokenExists() )
21 return false;
24 if( m_token == password )
26 // Token is one time use only
27 m_token = "";
28 return true;
30 else
32 return false;
36 std::string AuthToken::GetRoot( const std::string& login )
38 #ifdef SYMBIAN
39 return "E:";
40 #elif defined _WIN32
41 return "C:";
42 #else
43 return "/";
44 #endif
47 void AuthToken::GenerateToken()
49 int tokenLen = 6;
51 m_token.clear();
53 for( int i=0; i<tokenLen; i++ )
55 // 49: Start from 1 (0 is too similar to O)
56 // 122: End at z
57 // 7: Hole between 9 and A
58 // 6: Hole between Z and a
59 char c = rand() % ( 122 - 49 - 7 - 6 );
61 // Remove holes
62 c += 49;
63 if( c > 57 ) c += 7;
64 if( c > 90 ) c += 6;
66 m_token += c;
69 g_log->Print( std::string( "New token: " ) + m_token );
72 bool AuthToken::TokenExists()
74 return m_token != "";