[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

asp.net VB login

I have a form with a drop down displaying all the potential users that can log into my application. I also have a text box where the user will enter the password. I have made the password field from the SQL Connection on the dropdown list the DataValueKey. I want to validate that the password entered matches the password value stored for that users record and if it is go to a different web page. If it does not, display an error message.

This is the html I have so far...
<asp:DropDownList ID="UserName" runat="server"
                                                      DataSourceID="InterspanDataSource1" DataTextField="Name"
                                                      DataValueField="Password">
                                    </asp:DropDownList>
                                    <asp:SqlDataSource ID="InterspanDataSource1" runat="server"
                                                       ConnectionString="<%$ ConnectionStrings:InterspanResourcesConnectionString %>"
                                                       SelectCommand="SELECT DISTINCT [OperatorID], [Name], [Password], [SecurityLevel] F                                        FROM [qry_UserLogin]">
                                    </asp:SqlDataSource>
                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
                                                                ControlToValidate="UserName" ErrorMessage="User Name is required."
                                                                ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                   
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password: </asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="Password" runat="server" TextMode="Password"
                                                 ontextchanged="PasswordText_Changed"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
                                                                ControlToValidate="Password" ErrorMessage="Password is required."
                                                                ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>


This is the vb codebehind I have so far. This where I am struggling.

Protected Sub LoginButtonClick(sender As Object, e As EventArgs)
        If Login1.Password = Login1.UserName Then

        Else
            Login1.FailureText = Visible
        End If
    End Sub
0
rawilken
Asked:
rawilken
  • 2
2 Solutions
 
plusone3055Commented:
Protected Sub LoginButtonClick(sender As Object, e As EventArgs)
        If Login1.Password = Login1.UserName Then
           Response.Redirect("http://www.microsoft.com")
        Else
            Login1.FailureText = Visible
        End If
    End Sub
0
 
plusone3055Commented:
Protected Sub LoginButtonClick(sender As Object, e As EventArgs)
        If Login1.Password = Login1.UserName Then
           Response.Redirect("http://www.microsoft.com")
        Else
            Login1.FailureText.Visible= true
        End If
    End Sub
0
 
Alan WarrenCommented:
You need to match the text from the password textbox with the dropdownlist selected value (DataValueField).

If Password.text = UserName.SelectedValue Then
  ' Password is ok, do your login action here.
Else
   ' Notify failed login attempt stuff here
   
End if

Open in new window

Alan
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now