Exemplo n.º 1
0
        /// <summary>
        /// Set passord
        /// </summary>
        /// <param name="model">DTO password</param>
        /// <returns></returns>
        public async Task SetPassword(PasswordReq model)
        {
            var secretSplit = model.Secret.Split(':');

            if (secretSplit.Length != 2)
            {
                throw new AppLogicException("Nevalidní požadavek");
            }

            string modelHash = secretSplit[0];
            string email     = secretSplit[1];

            var user = await _context.Users
                       .Where(us => us.Email == email)
                       .FirstOrDefaultAsync();

            if (user == null)
            {
                throw new AppLogicException("Daný uživatel neexistuje");
            }

            string dbHash      = BitConverter.ToString(user.PasswordHash).Replace("-", "");
            bool   validSecret = modelHash == dbHash;

            if (!validSecret)
            {
                throw new AppLogicException("Nevalidní kód");
            }

            byte[] hash, salt;
            HashPassword(model.Password, out hash, out salt);

            user.PasswordHash = hash;
            user.PasswordSalt = salt;

            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task <ActionResult> SetPassword([FromBody] PasswordReq request)
        {
            await _userService.SetPassword(request);

            return(StatusCode(204));
        }
Exemplo n.º 3
0
 public PasswordUtil(int minLen, int maxLen, PasswordReq flags)
 {
     MinLength = minLen;
     MaxLength = maxLen;
     ReqFlags  = flags;
 }