retrive hashpassword data from database vb.net

Joined
Mar 29, 2006
Messages
1
Programming Experience
Beginner
HI,

i have done store into sqlserver database using vb.net application
the following code i was inserted into database.
Dim con As SqlConnection
Dim objcmd As SqlCommand
Dim sqlcmd As String
Dim result As Byte()
Dim salt(8) As Byte
Dim intermediate As String
Dim test As String = txtPassword.Text
Try
Dim sha As SHA1
sha =
New SHA1CryptoServiceProvider
Dim rng As RNGCryptoServiceProvider
rng =
New RNGCryptoServiceProvider
rng.GetBytes(salt)
intermediate = Convert.ToBase64String(salt) + test
result = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(intermediate))
MsgBox(Convert.ToBase64String(result))
Catch ce As CryptographicException
MsgBox(ce.Message)
End Try
con = New SqlConnection("server=localhost;uid=sa;password=cbl;database=msr")
con.Open()
sqlcmd = "INSERT INTO hashpass(username,password)VALUES (@Username, @Pass)"
objcmd =
New SqlCommand(sqlcmd, con)
objcmd.Parameters.Add("@Username", txtUsername.Text)
objcmd.Parameters.Add("@pass", result)
objcmd.ExecuteNonQuery()
con.Close()

----
now i want retrieve data from sqlserver database in vb.net application
please sent me the above problem
tq
j madhu
 
You don't actually have to get the record. When a user logs on you just need to check if a matching record exists, not actually retrieve it. You can hash your password and then execute a command like this:
VB.NET:
SELECT COUNT(*) FROM hashpass WHERE username = @username AND password = @password
You create an SqlCommand with that CommandText and call ExecuteScalar. The result will be zero if the user credentials are invalid and greater than zero if the are valid.

By the way, your profile says you're using VB 2005. The overload of Add you are using there has been deprecated in .NET 2.0, and the IDE would have told you so. You should change it to AddWithValue.
 
Back
Top