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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lalit MRank #1,186 · 1.5K reputationPosted Nov 13, 2009, 7:37 PM EST
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
keshav singhRank #3,113 · 460 reputationPosted Nov 13, 2009, 8:36 PM EST
it can convert string password to hash
A full description of the MD5 algorithm is available in rfc1321.
using System; using System.Text; using System.Security.Cryptography; // Create an md5 sum string of this string static public string GetMd5Sum(string str) { // First we need to convert the string into bytes, which // means using a text encoder. Encoder enc = System.Text.Encoding.Unicode.GetEncoder(); // Create a buffer large enough to hold the string byte[] unicodeText = new byte[str.Length * 2]; enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true); // Now that we have a byte array we can ask the CSP to hash it MD5 md5 = new MD5CryptoServiceProvider(); byte[] result = md5.ComputeHash(unicodeText); // Build the final string by converting each byte // into hex and appending it to a StringBuilder StringBuilder sb = new StringBuilder(); for (int i=0;i<result.Length;i++) { sb.Append(result[i].ToString("X2")); } // And return it return sb.ToString(); } you can also see that http://blog.stevex.net/?page_id=529 please check if this is helpful to ukeshav singhRank #3,113 · 460 reputationPosted Nov 13, 2009, 8:41 PM EST
http://www.etechplanet.com/post/2009/03/29/Generate-MD5-Hash-code-from-a-string-using-C.aspx
petre ricardo155 reputationPosted Nov 13, 2009, 8:58 PM EST
But i found what i;m looking for in home base's link! : )
petre