|
-
Feb 17th, 2003, 07:50 PM
#1
Thread Starter
New Member
Forms Authentication, Encrypted Passwords in SQL DB
I am trying to connect to a SQL Database and retrieve an encypted password. I have it working without encrypted passwords just using strings thanks to another post that lead me to the MS example artical:
http://support.microsoft.com/default...b;en-us;308157
I am not sure what to change to use encryted passwords. Any help would be appreciated.
Here is what I have so far.
Code:
Function ValidateUser(uid As string, passwd As string) As Boolean
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim retVal As Boolean = False
cnn = New SqlConnection("server=localhost;uid=sa;pwd=password;database=Pubs;")
cmd = New SqlCommand("Select * from users where uname = '" & uid & "'", cnn)
cnn.Open()
dr = cmd.ExecuteReader()
While (dr.Read())
If Strcomp(dr.Item("Pwd"), passwd, 1) = 0 Then
retVal = True
End If
End While
cnn.Close()
ValidateUser = retVal
End Function
-
Feb 17th, 2003, 10:39 PM
#2
PowerPoster
I got this code from a wrox book that I was reading. It seems like it will at least get you started. I am doing the same thing myself in C#. If you want all the code from the book, you can get it at this link:
http://web.wrox.com/download/code/pr...63_code_v7.zip
The book is called ASP.NET Website Programming at www.wrox.com
VB Code:
Public Shared Function ValidateLogin( _
ByVal emailAddress As String, _
ByVal password As String) _
As SitePrincipal
Dim moduleSettings As Configuration.ModuleSettings = _
Configuration.ModuleConfig.GetSettings()
Dim newId As Integer
Dim cryptPassword As Byte() = EncryptPassword(password)
Dim dataUser As New Data.User(moduleSettings.ConnectionString)
newId = dataUser.ValidateLogin(emailAddress, cryptPassword)
If newId > -1 Then
Return New SitePrincipal(newId)
Else
Return Nothing
End If
End Function
Public Shared Function EncryptPassword(ByVal password As String) As Byte()
Dim encoding As New UnicodeEncoding()
Dim hashBytes As Byte() = encoding.GetBytes(password)
' Compute the SHA-1 hash
Dim sha1 As New SHA1CryptoServiceProvider()
Dim cryptPassword = sha1.ComputeHash(hashBytes)
Return cryptPassword
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|