public async Task <UserEntity> LoginUser(string email, string password) { using (var cnn = _connectionFactory()) { try { cnn.Open(); var user = await cnn.QueryFirstOrDefaultAsync <UserEntity>( "usp_LoginUser", new { Email = email, Password = _hashProvider.GetHash(password) }, commandType : CommandType.StoredProcedure ); if (user == null) { throw new DbException("Login failed"); } return(user); } catch (SqlException ex) { if (HandleDbException(ex)) { throw; } } return(null); } }
/// <summary> /// Hashes password+salt /// </summary> /// <param name="user"></param> /// <param name="password"></param> /// <returns></returns> public string HashPassword(User user, string password) { if (user == null) { return(_hashProvider.GetHash(password)); } return(_hashProvider.GetHash(password + user.PasswordSalt)); }
public void ReturnsExpectedAvatarRoute(string emailAddress, string hash, string expectedRoute) { _hashProvider.GetHash(emailAddress).Returns(hash); var result = _serviceEndpointsProvider.GetAvatarRoute(emailAddress); _hashProvider.Received().GetHash(emailAddress); result.ShouldBe(expectedRoute); }
public async Task <User> Authorize(string userName, string password) { var user = await _databaseContext.Users.SingleOrDefaultAsync(a => a.UserName == userName); if (user == null) { return(null); } var hash = _hashProvider.GetHash(password); return(hash == user.PasswordHash ? user : null); }
public void ChangePin(string cardNumber, string oldPin, string newPin) { var card = _unitOfWork.CardRepository.GetByCardNumber(cardNumber); var _oldPin = _unitOfWork.CardRepository.GetByCardNumber(cardNumber).PinCode; var oldPinHash = _hashProvider.GetHash(oldPin); var newPinHash = _hashProvider.GetHash(newPin); if (_oldPin == oldPinHash) { card.PinCode = newPinHash; _unitOfWork.SaveChanges(); } }
public UserDto CreateUser(CreateUserDto userDto) { var user = _mapper.Map <Data.Entities.User>(userDto); user.PasswordHash = _hashProvider.GetHash(userDto.Password); if (!_validator.IsValid(user)) { throw new ArgumentException("User is invalid"); } _userRepository.CreateUser(user); return(_mapper.Map <UserDto>(user)); }
public UserStoreResponseCode Add(User user) { if (!userValidation.IsValidUserName(user)) { return(UserStoreResponseCode.InvalidUserName); } if (!userValidation.IsValidPassword(user)) { return(UserStoreResponseCode.InvalidPassword); } if (Find(user.UserName) != null) { return(UserStoreResponseCode.UserAlreadyExists); } try { userRepository.Add(new User { UserName = user.UserName, Password = hashProvider.GetHash(user.Password) }); } catch (Exception ex) { Logger.Instance.LogException(ex); return(UserStoreResponseCode.Error); } return(UserStoreResponseCode.Success); }
public bool Authorize(string cardNumber, string pin) { var pinHash = _hashProvider.GetHash(pin); var card = _unitOfWork.CardRepository.GetByCardNumber(cardNumber); return(card.PinCode == pinHash); }
private byte[] GetContentHash(IContent content) { using (var contentStream = content.GetReadStream()) { return(_hashProvider.GetHash(contentStream)); } }
async Task <AssetEntry <ISyncModel> > DownloadSyncModel <T>(string sourceId, SyncId id, CancellationToken token) where T : ISyncModel { var key = new StreamKey(sourceId, PersistentKey.GetKey <T>(id.Value)); var hash = m_HashProvider.GetHash(key); var syncModel = await DownloadSyncModel(key, hash, token); return(syncModel); }
/// <summary> /// Проверяет пароль на валидность /// </summary> /// <param name="manager">Менеджер пользователей</param> /// <param name="user">Пользователь</param> /// <param name="password">Пароль</param> /// <returns></returns> Task <IdentityResult> IPasswordValidator <User> .ValidateAsync(UserManager <User> manager, User user, string password) { var hash = _hashProvider.GetHash(password); if (hash == user.PasswordHash) { return(Task.FromResult(IdentityResult.Success)); } else { return(Task.FromResult(IdentityResult.Failed())); } }
public void AppendLine(string text) { Line line = new Line(_preprocessor.Trim(text), _hashProvider.GetHash(text)); if (TryAppendToCurrentLine(line)) { return; } text = _preprocessor.Preprocess(line.Text, Parameters.InstructionTokens); _line = line.ReplaceText(text); }
public UserAuthenticationResponseCode Authenticate(User user) { var foundUser = userRepository.Find(user.UserName); if (foundUser == null) { return(UserAuthenticationResponseCode.WrongUserName); } if (foundUser.Password != hashProvider.GetHash(user.Password)) { return(UserAuthenticationResponseCode.WrongPassword); } return(UserAuthenticationResponseCode.Success); }
public void AppendLine(string text) { Line line = new Line(_preprocessor.TrimStart(text), _hashProvider.GetHash(text)); if (TryAppendToLastLine(line)) { TryFinishMultilineOperation(line); return; } if (line.Text.StartsWithAny(InstructionTokens)) { text = PrepareToPush(line.Text); _lines.Push(line.ReplaceText(text)); TryStartMultilineOperation(line); TryFinishMultilineOperation(line); } }
public async Task SeedAll() { if (!await _databaseContext.Users.AnyAsync(a => a.UserName == "admin")) { var user = new User("admin", "", "", _hashProvider.GetHash("123123")); _databaseContext.Users.Add(user); await _databaseContext.SaveChangesAsync(); } if (!await _databaseContext.AccountTypes.AnyAsync()) { var acc1 = new AccountType(AccountTypeOption.BankAccount, "Банковский счет"); _databaseContext.AccountTypes.Add(acc1); var acc2 = new AccountType(AccountTypeOption.Cash, "Наличный расчет"); _databaseContext.AccountTypes.Add(acc2); await _databaseContext.SaveChangesAsync(); } }
public bool PasswordIsValid(TbaUser user, string password) { var hash = _hashProvider.GetHash(password); return(hash.Equals(user.PasswordHash)); }
public static void Initialize(ATMDataContext context, IHashProvider hashProvider) { if (!context.Users.Any()) { var users = new List <User> { new User { Name = "John Carlos", MobileNumber = 0723263400 }, new User { Name = "Tin Carlos", MobileNumber = 0723263401 }, new User { Name = "Dell Martin", MobileNumber = 0723263402 } }; context.Users.AddRange(users); context.SaveChanges(); } if (!context.Cards.Any()) { var Id1 = context.Users.First().Id; var Id2 = context.Users.Skip(1).FirstOrDefault().Id; var Id3 = context.Users.Skip(2).FirstOrDefault().Id; var cards = new List <Card> { new Card { Limit = 5000, ExpiryDate = new DateTime().AddYears(2), CSV = 123, PinCode = hashProvider.GetHash("4321"), User = context.Users.FirstOrDefault(u => u.Id == Id1), Balance = 4000, Type = CardType.Debit, CardNumber = "1234567890" }, new Card { Limit = 5000, ExpiryDate = new DateTime().AddYears(3), CSV = 456, PinCode = hashProvider.GetHash("1234"), User = context.Users.FirstOrDefault(u => u.Id == Id2), Balance = 4500, Type = CardType.Debit, CardNumber = "1234567891" }, new Card { Limit = 5000, ExpiryDate = new DateTime().AddYears(4), CSV = 789, PinCode = hashProvider.GetHash("5678"), User = context.Users.FirstOrDefault(u => u.Id == Id3), Balance = 4600, Type = CardType.Debit, CardNumber = "1234567892" }, }; context.Cards.AddRange(cards); context.SaveChanges(); } if (!context.Transactions.Any()) { var transactions = new List <Transaction> { new Transaction { Amount = 500, Balance = 4500, Dated = new DateTime().AddDays(3), CardId = context.Cards.FirstOrDefault().Id }, new Transaction { Amount = 400, Balance = 5500, Dated = new DateTime().AddDays(13), CardId = context.Cards.FirstOrDefault().Id }, new Transaction { Amount = 100, Balance = 5500, Dated = new DateTime().AddDays(5), CardId = context.Cards.FirstOrDefault().Id }, }; context.Transactions.AddRange(transactions); context.SaveChanges(); } }
public User GetUser(string login, string password) { var hash = _hashProvider.GetHash(password); return(Users.FirstOrDefault(user => user.Login == login && user.Password == hash)); }
public byte[] GetHash(Type type) { var hash = _hashProvider.GetHash(type.FullName); return(hash); }
public string GetAvatarRoute(string resource) { return($"/avatar/{_hashProvider.GetHash(resource)}"); }
/// <summary> /// Возвращает хеш пароля /// </summary> /// <param name="user">Пользователь</param> /// <param name="password">Пароль</param> /// <returns></returns> public string HashPassword(User user, string password) { return(_hashProvider.GetHash(password)); }