How to Compare the Value in TextBox With UserID&Password?

Discussion in 'ASP.NET 2.0' started by joelnet, Jul 13, 2006.

  1. What do you mean by compare a username and password?

    You want to lookup the username they typed into the textbox in the db and compare passwords?


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  2. Hello, i'm a new learner...
    i'd like to know if there's any source code that i can use to compare the value of textbox with UserName and Password in ASPNETDB.MDF?
    this isthe code, hope u can check and give a comment..

    <form id="form1" runat="server" language="javascript" onclick="return form1_onclick()" onsubmit="return form1_onsubmit()">

    <asp:FormView ID="FormView1" runat="server" DefaultMode="Insert" DataKeyNames="mohonID" DataSourceID="SqlDataSource2" Width="473px" BackColor="WhiteSmoke" BorderColor="WhiteSmoke" Height="201px" OnItemInserted="FormView1_ItemInserted">
    <InsertItemTemplate>
    <span style="font-size: 8pt">User Name</span>
    <asp:TextBox ID="UserNameTextBox" runat="server" MaxLength="12" Text='<%# Bind("UserName") %>' Font-Names="Tahoma" Font-Size="8pt" Width="136px"></asp:TextBox>

    <span style="font-size: 8pt; font-family: Tahoma">Password</span>
    <asp:TextBox ID="PasswordTextBox" TextMode="Password" runat="server" Text='<%# Bind("Password") %>' Font-Names="Tahoma" Font-Size="8pt" Width="135px"></asp:TextBox>

    <span style="font-size: 8pt; font-family: Tahoma">Code</span>
    <asp:DropDownList ID="Codeddl" runat="server" selectedvalue='<%# bind("Code") %>' AppendDataBoundItems="true" DataSourceID="SqlDataSourceCode" DataValueField="Code" DataTextField="Code" Font-Names="Tahoma" Font-Size="8pt" Width="127px"></asp:DropDownList>

    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Font-Bold="True" Text="Send"ForeColor="White" Font-Names="Tahoma" Font-Size="8pt" ></asp:LinkButton>

    <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" text=" Cancel" Font-Bold="True" ForeColor="White" Font-Names="Tahoma" Font-Size="8pt"></asp:LinkButton>
    </InsertItemTemplat



    </asp:FormView>


    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2%"InsertCommand="INSERT INTO [Test] ([UserName], [Password],
    Code:
    ) VALUES (@UserName, @Password, @Code)" ConflictDetection="CompareAllValues"> 
    
    
    
    
    
    <InsertParameters>
    
    
    <asp:Parameter Name="UserName" Type="String" />
    
    
    <asp:Parameter Name="Password" Type="String" />
    
    
    <asp:Parameter Name="Code" Type="String" />
    
    
    </InsertParameters>
    
    
    
    
    
    </asp:SqlDataSource>
    
    
    <asp:SqlDataSource ID="SqlDataSourceCode" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" SelectCommand="SELECT [Code]FROM [Test]">
    
    
    </asp:SqlDataSource>
    
    
    </form>
    
    
    Thanks..
     
  3. Thanks for reply..


    what i mean is,


    when user type in their username and password, it will check if it is available before it send the "username", "password" and "code" to the db.


    thanks.. i'm a new learner..
     
  4. Thanks for reply..


    How about if i'd like to compare the value that the user type-in in the textbox and then it will display the result.


    for example, if i type my code numbers, then it will display may name..


    thanks...
     
  5. wwv

    wwv

    The authentication / validation of a user against a database is a very specific , particular procedure. </o:p>
    I suppose, you mean two cases of a user validation:</o:p>
    <UL style="MARGIN-TOP: 0cm" type=disc>
    <LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt">new user</o:p>
    <LI class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt">registered user</o:p>[/list]
    </o:p>
    Usually a customer / user table has one or two unique keys and a password encrypted or not.</o:p>
    Correspondingly a Login form needs one text field for the key field and text field for the password.</o:p>
    For a new user, usually the user name is the key data. The application has to check, if the user name already exists. After successfully registration the user can gat an ID, which is also a unique key.</o:p>
    A registered user has to type in one key field and the password. The application looks in the database for the record with the key field, reads the password and compares with the password typed by the user.</o:p>
    </o:p>
    The both cases can be put together in an only one method.</o:p>
    </o:p>
    Have a fun!</o:p>
    Valentin</o:p>
    MCP C#</o:p>
    Do not hesitate to contact me!</o:p>
    www.wwv-it.eu </o:p>

    [email protected]</o:p>
    </o:p>
     
  6. Thanks a lot for reply..


    I've gota newidea from your website. [​IMG]
     
  7. wwv

    wwv

    To compare a text field with a numeric data: </o:p>
    either</o:p>
    · Convert the text field to numeric value, for instance: </o:p>
    int i0 = Convert.ToInt16 (TextBox1.Text);</o:p>
    int i0 = Convert.ToInt32 (TextBox1.Text);</o:p>
    or</o:p>
    · Convert the numeric data to a string variable:</o:p>
    string txt = n0.ToString ();</o:p>
    </o:p>
    then</o:p>
    </o:p>
    if (n0 == i0) ?</o:p>
    or</o:p>
    if (TextBox1.Text == txt) </o:p>
    </o:p>
    When the comparison is true store the values of the necessary record columns in variables and display them (you can read directly the column values in text controls)</o:p>
    </o:p>
    You can find an example on my site: http://www.wwv-it.com/WebCustomers</o:p>
    </o:p>
    Regards</o:p>
    </o:p>
    Valentin</o:p>
     

Share This Page