locked
Login control hash password SHA1 RRS feed

  • Question

  • User1028962535 posted

    Hello,

    I am trying to hash my password in an asp.net  login control before validating it in a database, but its not working, is this possible?

    Protected Sub ValidateUser(sender As Object, e As EventArgs)
    Dim userId As Integer = 0
    Dim roles As String = String.Empty
    Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Using con As New SqlConnection(constr)
    Using cmd As New SqlCommand("Validate_User")
    cmd.CommandType = CommandType.StoredProcedure

    Dim EncryptedPassword As String = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1") (NOT WORKING)
    cmd.Parameters.AddWithValue("@Username", Login1.UserName)
    cmd.Parameters.AddWithValue("@Password", Login1.EncryptedPassword)
    cmd.Connection = con

    con.Open()
    Dim reader As SqlDataReader = cmd.ExecuteReader()
    reader.Read()
    userId = Convert.ToInt32(reader("UserId"))
    roles = reader("Roles").ToString()
    con.Close()
    End Using
    Select Case userId
    Case -1
    Login1.FailureText = "Username and/or password is incorrect."
    Exit Select
    Case -2
    Login1.FailureText = "Account has not been activated."
    Exit Select

    thanks

    Dan

    Wednesday, July 11, 2018 2:53 PM

Answers

All replies