/// <summary> /// Инициализация данных БД /// </summary> /// <returns></returns> public async Task Initialize() { if (!await _databaseContext.Users.AnyAsync()) { #region Пользователи var adminSalt = new Random().GenerateSequence(16); var admin = new User() { Login = "******", Name = "SD", Email = "*****@*****.**", PasswordHash = _hashProvider.HashString("3228",adminSalt), // fX7nZzbZlODInUuDmW3RYg== PasswordSalt = adminSalt }; _databaseContext.Users.Add(admin); #endregion } await _databaseContext.SaveChangesAsync(); }
/// <summary> /// Регистрация /// </summary> /// <param name="registrationModel"></param> /// <returns></returns> public async Task Registration(RegistrationModel registrationModel) { var salt = Convert.ToString(Guid.NewGuid()); User user = new User { UserGuid = Guid.NewGuid(), Login = registrationModel.Login, Email = registrationModel.Mail, Name = registrationModel.Name, PasswordSalt = salt, PasswordHash = _hashProvider.HashString(registrationModel.Password) }; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); }
public static string HashString(string inputString, IHashProvider hashProvider, bool isCaseSensitive) { string result = null; if (inputString != null) { if (hashProvider != null) { if (!isCaseSensitive) { inputString = inputString.ToUpperInvariant(); } return(hashProvider.HashString(inputString)); } result = inputString; } return(result); }