Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > MD5 problems

Reply
Thread Tools

MD5 problems

 
 
Rudy
Guest
Posts: n/a
 
      03-14-2005
Hello all!

I'm working with the following code..

Function DBAuthenticate(ByVal strUsername As String, ByVal strPassword As
String) As Integer
Dim conLogin As SqlConnection
Dim cmdSelect As SqlCommand
Dim parmReturnValue As SqlParameter
Dim intResult As Integer

conLogin = New
SqlConnection("Server=localhost;UID=**;PWD=**;Data base=sample")
cmdSelect = New SqlCommand("DBAuthenticate", conLogin)
cmdSelect.CommandType = CommandType.StoredProcedure
parmReturnValue = cmdSelect.Parameters.Add("RETURN_VALUE",
SqlDbType.Int)
parmReturnValue.Direction = ParameterDirection.ReturnValue
cmdSelect.Parameters.Add("@username", strUsername)
cmdSelect.Parameters.Add("@password", strPassword)
'Encrypt the password
Dim md5Hasher As New MD5CryptoServiceProvider

Dim hashedDataBytes As Byte
Dim encoder As New UTF8Encoding

hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(strPassword ))

Dim paramPwd As SqlParameter
paramPwd = New SqlParameter("@password", SqlDbType.Binary, 16)
paramPwd.Value = hashedDataBytes
cmdSelect.Parameters.Add(paramPwd)

conLogin.Open()
cmdSelect.ExecuteNonQuery()
intResult = cmdSelect.Parameters("RETURN_VALUE").Value
conLogin.Close()
If intResult < 0 Then
If intResult = -1 Then
lblMessage.Text = "This guest is not registered."
Else
lblMessage.Text = "Sorry, invalid password."

End If
End If
Return intResult

End Function

with this line " hashedDataBytes =
md5Hasher.ComputeHash(encoder.GetBytes(strPassword ))" I am geting the
following error

'Public Overrides Function GetBytes(s As String) As Byte()': Value of
type 'System.Web.UI.WebControls.TextBox' cannot be converted to 'String'.


Any thoughts?

Rudy

 
Reply With Quote
 
 
 
 
Jason Brown [MSFT]
Guest
Posts: n/a
 
      03-14-2005
try

hashedDataBytes =
md5Hasher.ComputeHash(encoder.GetBytes(strPassword .ToString()))

I'm assuming your textbox is cdalled 'strpassword'?


--
Jason Brown
Microsoft GTSC, IIS

This posting is provided "AS IS" with no warranties, and confers no rights.

"Rudy" <> wrote in message
news:B9CB5253-5CA6-42F3-8844-...
> Hello all!
>
> I'm working with the following code..
>
> Function DBAuthenticate(ByVal strUsername As String, ByVal strPassword As
> String) As Integer
> Dim conLogin As SqlConnection
> Dim cmdSelect As SqlCommand
> Dim parmReturnValue As SqlParameter
> Dim intResult As Integer
>
> conLogin = New
> SqlConnection("Server=localhost;UID=**;PWD=**;Data base=sample")
> cmdSelect = New SqlCommand("DBAuthenticate", conLogin)
> cmdSelect.CommandType = CommandType.StoredProcedure
> parmReturnValue = cmdSelect.Parameters.Add("RETURN_VALUE",
> SqlDbType.Int)
> parmReturnValue.Direction = ParameterDirection.ReturnValue
> cmdSelect.Parameters.Add("@username", strUsername)
> cmdSelect.Parameters.Add("@password", strPassword)
> 'Encrypt the password
> Dim md5Hasher As New MD5CryptoServiceProvider
>
> Dim hashedDataBytes As Byte
> Dim encoder As New UTF8Encoding
>
> hashedDataBytes =
> md5Hasher.ComputeHash(encoder.GetBytes(strPassword ))
>
> Dim paramPwd As SqlParameter
> paramPwd = New SqlParameter("@password", SqlDbType.Binary, 16)
> paramPwd.Value = hashedDataBytes
> cmdSelect.Parameters.Add(paramPwd)
>
> conLogin.Open()
> cmdSelect.ExecuteNonQuery()
> intResult = cmdSelect.Parameters("RETURN_VALUE").Value
> conLogin.Close()
> If intResult < 0 Then
> If intResult = -1 Then
> lblMessage.Text = "This guest is not registered."
> Else
> lblMessage.Text = "Sorry, invalid password."
>
> End If
> End If
> Return intResult
>
> End Function
>
> with this line " hashedDataBytes =
> md5Hasher.ComputeHash(encoder.GetBytes(strPassword ))" I am geting the
> following error
>
> 'Public Overrides Function GetBytes(s As String) As Byte()': Value of
> type 'System.Web.UI.WebControls.TextBox' cannot be converted to 'String'.
>
>
> Any thoughts?
>
> Rudy
>



 
Reply With Quote
 
 
 
 
Rudy
Guest
Posts: n/a
 
      03-14-2005
Hi Jason!

Actually, my textbox is "txtnicPass.text"

hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(txtnicPass. Text))

Sorry, I forgot to change to my original code, and problem. So with this, I
get this error
" Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'."

Any ideas?

Thanks!

Rudy





"Jason Brown [MSFT]" wrote:

> try
>
> hashedDataBytes =
> md5Hasher.ComputeHash(encoder.GetBytes(strPassword .ToString()))
>
> I'm assuming your textbox is cdalled 'strpassword'?
>
>
> --
> Jason Brown
> Microsoft GTSC, IIS
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Rudy" <> wrote in message
> news:B9CB5253-5CA6-42F3-8844-...
> > Hello all!
> >
> > I'm working with the following code..
> >
> > Function DBAuthenticate(ByVal strUsername As String, ByVal strPassword As
> > String) As Integer
> > Dim conLogin As SqlConnection
> > Dim cmdSelect As SqlCommand
> > Dim parmReturnValue As SqlParameter
> > Dim intResult As Integer
> >
> > conLogin = New
> > SqlConnection("Server=localhost;UID=**;PWD=**;Data base=sample")
> > cmdSelect = New SqlCommand("DBAuthenticate", conLogin)
> > cmdSelect.CommandType = CommandType.StoredProcedure
> > parmReturnValue = cmdSelect.Parameters.Add("RETURN_VALUE",
> > SqlDbType.Int)
> > parmReturnValue.Direction = ParameterDirection.ReturnValue
> > cmdSelect.Parameters.Add("@username", strUsername)
> > cmdSelect.Parameters.Add("@password", strPassword)
> > 'Encrypt the password
> > Dim md5Hasher As New MD5CryptoServiceProvider
> >
> > Dim hashedDataBytes As Byte
> > Dim encoder As New UTF8Encoding
> >
> > hashedDataBytes =
> > md5Hasher.ComputeHash(encoder.GetBytes(strPassword ))
> >
> > Dim paramPwd As SqlParameter
> > paramPwd = New SqlParameter("@password", SqlDbType.Binary, 16)
> > paramPwd.Value = hashedDataBytes
> > cmdSelect.Parameters.Add(paramPwd)
> >
> > conLogin.Open()
> > cmdSelect.ExecuteNonQuery()
> > intResult = cmdSelect.Parameters("RETURN_VALUE").Value
> > conLogin.Close()
> > If intResult < 0 Then
> > If intResult = -1 Then
> > lblMessage.Text = "This guest is not registered."
> > Else
> > lblMessage.Text = "Sorry, invalid password."
> >
> > End If
> > End If
> > Return intResult
> >
> > End Function
> >
> > with this line " hashedDataBytes =
> > md5Hasher.ComputeHash(encoder.GetBytes(strPassword ))" I am geting the
> > following error
> >
> > 'Public Overrides Function GetBytes(s As String) As Byte()': Value of
> > type 'System.Web.UI.WebControls.TextBox' cannot be converted to 'String'.
> >
> >
> > Any thoughts?
> >
> > Rudy
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a md5 / md5 passwd with a salt Peter Woodsky Ruby 6 11-21-2008 09:08 AM
md5 from python different then md5 from command line ursache.marius@gmail.com Python 9 05-07-2006 11:49 PM
How to generate an MD5 data from the string Peter Afonin ASP .Net 3 08-24-2004 09:09 AM
I remember someone asking about an MD5 javascript: http://pajhome.org.uk/crypt/md5/ Mozzie ³ »\( òvó \)« Javascript 0 07-12-2004 01:06 PM
MD5 security probems on a 2620 Ed Pacheco Cisco 3 02-10-2004 01:52 AM



Advertisments