start working on User and Group classes

- User and Group has been moved to 'models' directory
- removed UserPass struct (passwords fields were put to User struct)
not working yet, we need support for binary blobs in morm
This commit is contained in:
2021-04-30 01:34:48 +02:00
parent ccda2bc2fd
commit 4277f90bad
29 changed files with 363 additions and 200 deletions

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,22 +55,21 @@ Login::Login()
void Login::ClearTmpStruct()
{
system->crypt.ClearString(pass_decrypted);
system->crypt.ClearString(pass_hashed);
system->crypt.ClearString(up.pass);
system->crypt.ClearString(up.pass_encrypted);
system->crypt.ClearString(up2.pass);
system->crypt.ClearString(up2.pass_encrypted);
// system->crypt.ClearString(up.pass);
// system->crypt.ClearString(up.pass_encrypted);
// system->crypt.ClearString(up2.pass);
// system->crypt.ClearString(up2.pass_encrypted);
}
bool Login::CheckPasswords(const std::wstring & password)
bool Login::CheckPasswords(User & user, const std::wstring & password)
{
if( !up.pass_encrypted.empty() )
if( !user.pass_encrypted.empty() )
{
if( system->crypt.RSA(false, config->pass_rsa_private_key, up.pass_encrypted, pass_decrypted) )
if( system->crypt.RSA(false, config->pass_rsa_private_key, user.pass_encrypted, pass_decrypted) )
{
PT::UTF8ToWide(pass_decrypted, up.pass);
PT::UTF8ToWide(pass_decrypted, user.password);
}
else
{
@@ -79,22 +78,22 @@ bool Login::CheckPasswords(const std::wstring & password)
}
}
pass_hashed = password;
up2.pass_type = up.pass_type;
up2.pass = password;
std::wstring password_from_db = user.password;
user.password = password;
if( up.pass_hash_salted )
if( user.pass_hash_salted )
salt = config->pass_hash_salt;
else
salt.clear();
if( !system->crypt.PassHash(salt, up2) )
if( !system->crypt.PassHash(salt, user) )
{
log << log1 << "Login: I cannot hash a password, login failure" << logend;
return false;
}
bool result = (up.pass == up2.pass);
// compare char by char until the end of the strings (time attacks)
bool result = (user.password == password_from_db);
if( !result )
log << log2 << "Login: incorrect login/password" << logend;
@@ -114,15 +113,25 @@ bool Login::CheckUserPass(const std::wstring & login, const std::wstring & passw
{
bool result;
if( db->GetUserPass(login, user_id, up) )
morm::Finder<User> finder(model_connector);
User user = finder.
select().
where().
eq(L"login", login).
get();
if( user.found() )
{
if( up.has_pass )
user_id = user.id;
if( user.has_pass )
{
result = CheckPasswords(password);
result = CheckPasswords(user, password);
}
else
{
log << log2 << "Login: this account has not a password set yet" << logend;
log << log2 << "Login: this account has no a password set yet" << logend;
result = false;
}
}