如何以哈希格式存储密码并在登录时进行比较 [英] how to store password in Hash format and compare while login

查看:327
本文介绍了如何以哈希格式存储密码并在登录时进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在VB.NET中开发应用程序,我希望我的应用程序受到保护,这就是为什么我想知道如何加密密码并将哈希字符串存储到数据库中的原因.
并且在用户登录时,应将密码转换为哈希,然后将comapre转换为存储的密码并授权用户.

谢谢.

Hello friends,
i am developing an application in VB.NET and i want my application to be secured and that is why i want to know how can i encrypt the password and store the hash string into Database.

and when user logs-in it should convert the password into hash and comapre to the stored password and authorise the user.

Thanks.

推荐答案

在这里尝试: ^ ]


导入System.Text
导入System.Security.Cryptography

公共函数computeHash(ByVal strPassword As String)As String
Dim plainTextBytes()As Byte = Encoding.UTF8.GetBytes(strPassword)
昏暗散列为HashAlgorithm =新的SHA256Managed()
Dim hashBytes()As Byte = hash.ComputeHash(plainTextBytes)
昏暗的哈希值作为字符串= Convert.ToBase64String(hashBytes)
返回哈希值
最终功能
通过使用上述功能,可以对密码进行加密,并将加密后的字符串存储到数据库中.登录时,将文本框的哈希值与您保存的数据库值进行比较.
Imports System.Text
Imports System.Security.Cryptography

Public Function computeHash(ByVal strPassword As String) As String
Dim plainTextBytes() As Byte = Encoding.UTF8.GetBytes(strPassword)
Dim hash As HashAlgorithm = New SHA256Managed()
Dim hashBytes() As Byte = hash.ComputeHash(plainTextBytes)
Dim hashvalue As String = Convert.ToBase64String(hashBytes)
Return hashvalue
End Function
By using the above function encrypt your password and store the encrypted string into database. On login compare the hash value of textbox with the database value that you have saved.


这篇关于如何以哈希格式存储密码并在登录时进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆