public async Task <Account> LoginAsync(LoginAccount command) { var account = await _context.Accounts.GetByLoginOrEmail(command.LoginOrEmail).SingleOrDefaultAsync(); if (account == null) { throw new CorruptedOperationException("Account doesn't exist"); } var isPasswordCorrect = _passwordManager.VerifyPasswordHash(command.Password, account.PasswordHash, account.Salt); if (isPasswordCorrect == false) { throw new CorruptedOperationException("Wrong credentials"); } return(account); }
public async Task <Account> LoginAccountAsync(LogInCommand command) { var account = await Task.FromResult(_context.Accounts.SingleOrDefault(x => x.Login.ToLowerInvariant() == command.Login.ToLowerInvariant())); if (account == null) { throw new InternalSystemException("There is no account with given credentials."); } var isPasswordCorrect = _passwordManager.VerifyPasswordHash(command.Password, account.PasswordHash, account.Salt); if (isPasswordCorrect == false) { throw new InternalSystemException("Wrong credentials."); } return(account); }
public async Task <MemberLoggedInDto> Login(MemberToLoginDto memberToLoginDto) { var memberEntity = await GetMember(memberToLoginDto.LoginName, memberToLoginDto.EmailAddress); if (memberEntity != null) { var memberEntityDto = _mapper.Map <MemberEntityDto>(memberEntity); var memberLoggedInDto = _mapper.Map <MemberLoggedInDto>(memberEntity); if (_passwordManager.VerifyPasswordHash( memberToLoginDto.Password, memberEntityDto.PasswordHash, memberEntityDto.PasswordSalt)) { memberLoggedInDto.Token = _tokenManager.CreateToken( memberLoggedInDto.Id, memberLoggedInDto.LoginName, memberLoggedInDto.ProfilePictureUrl); return(memberLoggedInDto); } } // If this clause is reached it means the member was not found or the password is wrong. throw new MemberLoginException(); }