Exemple #1
0
 public DatabaseUser(UserSettings userSettings)
 {
     UserId          = userSettings.UserId;
     Username        = userSettings.Username;
     EmailAddress    = userSettings.EmailAddress;
     FirstName       = userSettings.FirstName;
     LastName        = userSettings.LastName;
     Salt            = UserPasswordTools.GenerateRandomPasswordSalt();
     Password        = UserPasswordTools.HashAndSaltPassword(userSettings.Password, this.Salt);
     IsAdministrator = userSettings.IsAdministrator;
 }
Exemple #2
0
        public bool ModifyPassword(UserPassword userPassword)
        {
            if (userPassword.UserId != null)
            {
                DatabaseUser dbUser = _dbQueryService.GetUserById(userPassword.UserId.Value);
                string       saltedHashedPasswordToCheck =
                    UserPasswordTools.HashAndSaltPassword(userPassword.OldPassword, dbUser.Salt);
                // If the salted and hashed passwords are identical, then we have a match.
                if (saltedHashedPasswordToCheck == dbUser.Password)
                {
                    dbUser.Salt     = UserPasswordTools.GenerateRandomPasswordSalt();
                    dbUser.Password = UserPasswordTools.HashAndSaltPassword(userPassword.NewPassword, dbUser.Salt);
                    return(_dbQueryService.PersistPasswordChange(dbUser));
                }
            }

            return(false);
        }
Exemple #3
0
        public UserSettings CreateAndReturnUser(UserSettings userSettings)
        {
            DatabaseUser dbUser = new DatabaseUser(userSettings);

            dbUser.Salt     = UserPasswordTools.GenerateRandomPasswordSalt();
            dbUser.Password = UserPasswordTools.HashAndSaltPassword(userSettings.Password, dbUser.Salt);
            dbUser.EscapeStringFields();
            if (_dbQueryService.PersistNewUser(dbUser))
            {
                UserSettings createdUser = GetUserByUsername(userSettings.Username);
                createdUser.CreateAPIKey = userSettings.CreateAPIKey;
                if (createdUser.CreateAPIKey)
                {
                    createdUser.APIKey = _apiKeyService.RegisterNewAPIKey(createdUser.UserId);
                }
                return(createdUser);
            }

            return(null);
        }
Exemple #4
0
        public bool ResetPassword(PasswordReset passwordReset)
        {
            DatabaseUser databaseUser = _dbQueryService.GetUserByPasswordResetToken(passwordReset.Token);

            if (databaseUser == null)
            {
                return(false);
            }

            databaseUser.Salt     = UserPasswordTools.GenerateRandomPasswordSalt();
            databaseUser.Password = UserPasswordTools.HashAndSaltPassword(passwordReset.Password, databaseUser.Salt);

            if (_dbQueryService.PersistPasswordChange(databaseUser))
            {
                _dbQueryService.PersistRemovePasswordResetToken(passwordReset.Token);
                return(true);
            }

            return(false);
        }