Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

How to verify hash password with db.password?

$
0
0

Dear all, 

I am trying verify the createdpasswordHash with u.username.  Do i need to create a new method for this or can I just amend the exsiting 'validate' method.  

  private static string CreateSalt()
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] buff = new byte[32];
            rng.GetBytes(buff);

            return Convert.ToBase64String(buff);
        }

        private static string CreatePasswordHash(string pwd, string salt)
        {
            string saltAndPwd = String.Concat(pwd, salt);
            string hashedPwd =
                    FormsAuthentication.HashPasswordForStoringInConfigFile(
                    saltAndPwd, "sha1");
            return hashedPwd;
        }

        public api_login Validate2(string userName, string Password)
        {
            // Find a user that matches that username and password (this will only validate if both match)
            return db.api_login.FirstOrDefault(u => u.username == userName && u.password == Password);
        }

Any help will be most appreciated. Many thanks. 


Viewing all articles
Browse latest Browse all 4737

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>