public bool Login(string email, string password) { var user = _userService.Login(email); var hash = HasherExtension.VerifyHashedPassword(user.PasswordHash, password); return(hash); }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity <User>().HasData( new User { UserName = "******", PasswordHash = HasherExtension.HashPassword("123"), }); }
public override async Task <Users> InsertAsync(Users user) { var _user = await _userRepository.GetUserByEmailAsync(user); if (_user != null) { return(null); } user.PasswordHash = HasherExtension.HashPassword(user.PasswordHash); return(await _userRepository.InsertAsync(user)); }
public bool Verify(User user) { var result = _userManager.Users.FirstOrDefault(x => x.UserName.Equals(user.UserName)); var verify = HasherExtension.VerifyHashedPassword(result.PasswordHash, user.PasswordHash); if (verify) { return(true); } return(false); }
public async Task <AcessToken> GetAcessTokenByLoginAsync(User user) { var _user = await _userRepository.GetUserByEmailAsync(user); if (_user != null) { var result = HasherExtension.VerifyHashedPassword(_user, _user.PasswordHash, user.PasswordHash); if (result) { return(await _tokenService.CreateTokenByEmailAsync(_user)); } } return(null); }
public ActionResult Cadastro(CadastroDTO cadastroDTO) { if (!ModelState.IsValid) { return(BadRequest(cadastroDTO)); } var user = _mapper.Map <User>(cadastroDTO); user.PasswordHash = HasherExtension.HashPassword(user.PasswordHash); var verifyEmail = _userAppService.VerifyEmail(user.Email); if (verifyEmail) { return(BadRequest("E-mail já existente")); } _userAppService.Insert(user); _userAppService.Commit(); return(new ObjectResult(cadastroDTO)); }
public async Task <Users> GetUserByLoginAsync(Users user) { var _user = await _userRepository.GetUserByEmailAsync(user); if (_user == null) { return(null); } var password = HasherExtension.VerifyHashedPassword(_user.PasswordHash, user.PasswordHash); if (!password) { return(null); } var token = await _authenticationService.CreateJwtTokenAsync(_user); _user.Token = token; _user.LastLogin = DateTime.Now; return(await _userRepository.UpdateAsync(_user)); }