public void SetHashPassword(string pw) { var ho = new HashingOptions(); var pwh = new PasswordHasher(ho); Password = pwh.Hash(pw); }
public ActionResult <AuthView> Authenticate( [FromServices] DataContext context, [FromBody] AuthRequest model) { // Recupera o usuário var userQuery = context.users.AsQueryable(); User user = userQuery .Where(x => x.Email.ToLower().Contains(model.Email)).First(); var option = new HashingOptions(); var password = new PasswordHasher(Options.Create(option)); var(verified, _) = (password.Check(user.Password, model.Password)); if (verified) { // Gera o Token var token = TokenService.GenerateToken(user, Configuration.GetConnectionString("Secret")); // Retorna os dados return(new AuthView() { user = new UserView(user), token = token }); } var e = new Exception("Login inválido"); return(BadRequest(e.Message)); }
/// <summary> /// Check login /// </summary> public OUser checkLogin(string username, string password) { OUser login = null; HashingOptions hashingOptions = new HashingOptions(); hashingOptions.Iterations = 1000; IOptions <HashingOptions> options = Options.Create(hashingOptions); PasswordHasher hasher = new PasswordHasher(options); User user = context.Users.AsNoTracking() .FirstOrDefault(u => u.uLogin == username); if (user == null) { throw new Exception("User not found"); } var check = hasher.Check(user.uPassword, password); if (!check.Verified) { throw new Exception("Incorrect password"); } else { UserManager userManager = new UserManager(context); login = userManager.convert(user); } return(login); }
private string hashPassword(string password) { HashingOptions hashingOptions = new HashingOptions(); hashingOptions.Iterations = 1000; IOptions <HashingOptions> options = Options.Create(hashingOptions); PasswordHasher hasher = new PasswordHasher(options); return(hasher.Hash(password)); }
public UserService( IMapper mapper, ILogger logger, TextBookerContext db, IMailSender mailSender, JwtSettings jwtSettings, GoogleSettings googleOptions, IHttpClientFactory clientFactory, IHttpContextAccessor httpContextAccessor ) : base(logger) { this.mapper = mapper; this.db = db; this.mailSender = mailSender; this.jwtSettings = jwtSettings; this.googleOptions = googleOptions; this.clientFactory = clientFactory; httpContext = httpContextAccessor.HttpContext; baseUrl = $"{httpContext.Request.Scheme}://{httpContext.Request.Host}{httpContext.Request.PathBase}"; var hashOptions = new HashingOptions(); passwordHasher = new PasswordHasher(hashOptions); }
public PasswordHasher(IOptions <HashingOptions> options) { _options = options.Value; }
public PasswordHasher(HashingOptions options) { Options = options; }
public PasswordHasher(IOptions <HashingOptions> hashingOptions) { HashingOptions = hashingOptions.Value; }