I have this code which displays a login form, i want to encrypt the password before it stores into the sql database and should also be able to verify the pwd when a user logs in.
Please help me, it'll be very greateful of you, Thank you.

Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click

    Try

        If constring.State = ConnectionState.Open Then
            constring.Close()
        End If
        constring.Open()

        Dim MainMenu As New MDIParent1
        Dim result As String
        Dim CMD As New SqlCommand
        CMD.Connection = constring


        CMD.CommandText = "Exec validatelogin '" & txtuserid.Text & "','" & txtpwd.Text & "'"
        Dim ad As New SqlDataAdapter(CMD)
        Dim dt As New DataTable

        result = CMD.ExecuteScalar
        ad.Fill(dt)
        MsgBox(result, MsgBoxStyle.Exclamation)


        If result = "True" And CheckBox1.CheckState = 0 Then

            MainMenu.Show()
            Me.Dispose(False)

        Else
            MsgBox("Username or Password appears to be wrong")

        End If


        constring.Close()
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.ApplicationModal)
    End Try


End Sub


Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

    Dim result As String
    Dim CMD As New SqlCommand
    CMD.Connection = constring

    Try
        If constring.State = ConnectionState.Open Then
            constring.Close()
        End If
        constring.Open()


        If CheckBox1.CheckState = 1 Then
            CMD.CommandText = "Exec validatelogin '" & txtuserid.Text & "','" & txtpwd.Text & "'"
            Dim ad As New SqlDataAdapter(CMD)
            Dim dt As New DataTable

            result = CMD.ExecuteScalar
            ad.Fill(dt)

            If result = "True" Then
                Height = 655
                Width = 466

            Else
                MsgBox("Username or Password appears to be wrong")
            End If

        ElseIf CheckBox1.CheckState = 0 Then
            Height = 289
            Width = 462

        End If

        constring.Close()

    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.ApplicationModal)
    End Try


End Sub


Private Sub btnSave_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

    Try

        Dim sqlparameter(2) As Object
        sqlparameter(0) = txtuserid.Text
        sqlparameter(1) = txtoldpwd.Text
        sqlparameter(2) = txtnewpwd.Text


        While CheckBox1.CheckState = 1
            If constring.State = ConnectionState.Open Then
                constring.Close()
            End If

            constring.Open()
            Dim CMD As New SqlCommand
            CMD.Connection = constring
            Dim commandstring As String = " '"
            Dim msg As String
            Dim ad As New SqlDataAdapter
            Dim dt As New DataTable



            For Each Str As String In sqlparameter
                commandstring &= Str & "','"
            Next

            If String.IsNullOrEmpty(txtuserid.Text) OrElse String.IsNullOrEmpty(txtpwd.Text) OrElse String.IsNullOrEmpty(txtoldpwd.Text) OrElse String.IsNullOrEmpty(txtnewpwd.Text) Then

                MsgBox("All fields need to be filled")
                Exit Sub

            End If

            commandstring = Mid(commandstring, 1, (Len(commandstring) - 2))

            CMD.CommandText = "Exec updatelog " & commandstring
            msg = CMD.ExecuteScalar()
            'ad.Fill(dt)


            If txtoldpwd.Text = txtpwd.Text Then
                MsgBox("password changed")
                Exit Sub
            Else
                MsgBox("password is mismatched")
                Exit Sub
            End If
            constring.Close()

        End While

    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.ApplicationModal)


    End Try


End Sub

First step is to search this forum. That's what the big SEARCH box at the top is for. If you do that you will find

this code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.