Hi,
1. I need to convert my password string to hash value, how do i do this and vise versa?
2. How do i create a salt value for a password?
3. How do i extract the salt value from the password hash?
thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Lalit MPosted Nov 14, 2009, 12:37 AM
You Can try this code
First Part takes in a simple user name and password to convert a concatanated string of both to a MD5 hash. Second part of the program is to convert the byte output of has to a simple representable HEX string format which would actually used to display and store.
<script language=vb runat=server>
sub getHash(sender as Object, e as EventArgs)
' Get the name and password and concatanate it
Dim inputPassword as string
inputPassword = Request.Form("name") & Request.Form("password")
Response.write("The String to Hash is = " & inputPassword & "
")
'this utility class aides in converting string to bye array which is what out has implementation needs
Dim encode as new System.Text.UnicodeEncoding
Dim inputPasswordBytes() as byte = encode.GetBytes(inputPassword)
Dim hash() as byte
' get hash
dim md5 as new System.Security.Cryptography.MD5CryptoServiceProvider
hash = md5.ComputeHash(inputPasswordBytes)
' convert hash value to hex string
dim sb as new System.Text.StringBuilder
dim outputByte as byte
for each outputByte in hash
' convert each byte to a Hexadecimal upper case string
sb.Append(outputByte.ToString("x2").ToUpper)
next outputByte
Response.write("The hash is = " & sb.ToString)
end sub
script>
<head>
<title>MD5 sampletitle>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
Name: <asp:TextBox Runat=server TextMode=SingleLine ID="name" />
Password: <asp:TextBox Runat=server TextMode=Password ID="password" />
<asp:Button Runat=server OnClick=getHash Text=getHash />
form>
body>
html>
About Password Using a Random Salt
petre ricardoPosted Nov 14, 2009, 1:58 AM
But i found what i;m looking for in home base's link! : )
petre
keshav singhPosted Nov 14, 2009, 1:41 AM
http://www.etechplanet.com/post/2009/03/29/Generate-MD5-Hash-code-from-a-string-using-C.aspx
keshav singhPosted Nov 14, 2009, 1:36 AM
it can convert string password to hash
A full description of the MD5 algorithm is available in rfc1321.