public void SetHashPassword(string pw)
        {
            var ho  = new HashingOptions();
            var pwh = new PasswordHasher(ho);

            Password = pwh.Hash(pw);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        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;
 }
Exemple #8
0
 public PasswordHasher(IOptions <HashingOptions> hashingOptions)
 {
     HashingOptions = hashingOptions.Value;
 }