Esempio n. 1
0
        public hashResponse hashVerify(hashVerifyRequest hashRequest)
        {
            var response   = new hashResponse();
            int iterations = hashRequest.iterations.HasValue ? (int)hashRequest.iterations : 36000;

            try
            {
                switch (hashRequest.Algorithm)
                {
                case "bcrypt":
                    response.Matched = BCrypt.Net.BCrypt.Verify(hashRequest.Password, hashRequest.HashedPassword);
                    break;

                case "sha256":
                    byte[] salt           = Encoding.ASCII.GetBytes(hashRequest.Salt);
                    var    hashedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                                       password: hashRequest.Password,
                                                                       salt: salt,
                                                                       prf: KeyDerivationPrf.HMACSHA256,
                                                                       iterationCount: iterations,
                                                                       numBytesRequested: 256 / 8));
                    response.Matched = hashedPassword == hashRequest.HashedPassword;
                    break;
                }
            }
            catch (System.Exception e)
            {
                response.Message = e.Message;
            }
            return(response);
        }
Esempio n. 2
0
 public IActionResult Verify([FromBody] hashVerifyRequest request)
 {
     return(Ok(_hashesService.hashVerify(request)));
 }