MD5 problems

Discussion in 'ASP .Net Security' started by Rudy, Mar 14, 2005.

  1. Rudy

    Rudy Guest

    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=**;Database=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
     
    Rudy, Mar 14, 2005
    #1
    1. Advertising

  2. 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:...
    > 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=**;Database=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
    >
     
    Jason Brown [MSFT], Mar 14, 2005
    #2
    1. Advertising

  3. Rudy

    Rudy Guest

    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:...
    > > 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=**;Database=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
    > >

    >
    >
    >
     
    Rudy, Mar 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Afonin

    How to generate an MD5 data from the string

    Peter Afonin, Aug 20, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    499
  2. Peter Afonin

    MD5 conversion problem

    Peter Afonin, Aug 27, 2004, in forum: ASP .Net
    Replies:
    15
    Views:
    807
    Peter Afonin
    Sep 1, 2004
  3. Jason Williard

    Encrypt Password w/MD5

    Jason Williard, Oct 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    601
    Steve C. Orr [MVP, MCSD]
    Oct 17, 2004
  4. Replies:
    9
    Views:
    17,211
    John Salerno
    May 8, 2006
  5. Peter Woodsky

    create a md5 / md5 passwd with a salt

    Peter Woodsky, Nov 20, 2008, in forum: Ruby
    Replies:
    6
    Views:
    242
    Brian Candler
    Nov 21, 2008
Loading...

Share This Page