public CreateBCryptHash ( string password ) : void | ||
password | string | The plain text password to hash |
Результат | void |
public void CreateBCryptHash(string password)
{
if (password.Trim().Length < Math.Max(4, TShock.Config.MinimumPasswordLength))
{
throw new ArgumentOutOfRangeException("password", "Password must be > " + TShock.Config.MinimumPasswordLength + " characters.");
}
try
{
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), TShock.Config.BCryptWorkFactor);
}
catch (ArgumentOutOfRangeException)
{
TShock.Log.ConsoleError("Invalid BCrypt work factor in config file! Creating new hash using default work factor.");
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim());
}
}
User::CreateBCryptHash ( string password, int workFactor ) : void |
/// <summary> /// Sets the Hashed Password for a given username /// </summary> /// <param name="user">User user</param> /// <param name="password">string password</param> public void SetUserPassword(User user, string password) { try { user.CreateBCryptHash(password); if ( _database.Query("UPDATE Users SET Password = @0 WHERE Username = @1;", user.Password, user.Name) == 0) { throw new UserNotExistException(user.Name); } } catch (Exception ex) { throw new UserManagerException("SetUserPassword SQL returned an error", ex); } }