how to check username and password from database in using c#

how to check username and password from database in using c#

how to check username and password from database in using c#

In this Post We Will Explain About is how to check username and password from database in using c# With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to login form in c# with source code Example

In this post we will show you Best way to implement login and registration form in with database, hear for registration form in with c# code with validation with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

how to check username and password from database in using c#

In this Example,First of all Add or Inluce External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priorty set.After that Include your relavant CSS Class.

Read Also:  jQuery Check an Element is Visible or not



And Then make a Stored Procedure like as a check the simple log in attempt as:

CREATE PROCEDURE simple_user_Login_check
                @liveuname varchar(100),
                @livepass    varchar(100)
                select * from table_login
                where uname COLLATE [email protected]
                and [Password] COLLATE [email protected]
In the web.config file create the connection string to connect the web application with the sql server database as.
    <add name="conStr" connectionString="Data Source=lalit;Initial Catalog=MyDataBase;Integrated Security=True"/>

HTML Source Code

In the HTML :

simple tag of the design page like as a (.aspx) place two created textbox controls means two textbox and a simple make Button and a label some controls and design the here Sign in page as:

    <fieldset style="width:280px">
    <legend>Login example in</legend>
    <td>User Name: * </td><td>
        <asp:TextBox ID="liveUname" runat="server"></asp:TextBox><br />
            ID="rfvUserName" runat="server" ErrorMessage="Please enter Uniq UsersName"
            Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
    <td>Password: *</td><td>
        <asp:TextBox ID="livepass_txt" runat="server" TextMode="Password"></asp:TextBox><br />
            ID="rfvPwd" runat="server" ErrorMessage="Please enter password"
            Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
     <td> </td>
        <asp:Button ID="login_btn" runat="server" Text="Login"
            onclick="userLogin_sub" /></td>
     <td> </td>
         <asp:Label ID="labelsta" runat="server" Text=""></asp:Label>

Asp.Net C# code

Asp.Net C# source code to make Login page or html form and check foruser auth like as a liveuname and password.

Read Also:  Simple vue.js Conditional Directives

First of all include the some external following some namespaces

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

And then write the some source code as:

protected void userLogin_sub(object sender, EventArgs e)
        DataTable dtable = new DataTable();
        SqlDataAdapter sqladpl = new SqlDataAdapter();    
            SqlConnection dbcon = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
            SqlCommand live_cmd = new SqlCommand("simple_user_Login_check", dbcon);
            live_cmd.CommandType = CommandType.StoredProcedure;
            live_cmd.Parameters.AddWithValue("@liveuname", liveUname.Text.Trim());
            live_cmd.Parameters.AddWithValue("@livepass", livepass_txt.Text.Trim());
            sqladpl.SelectCommand = live_cmd;          
            if (dtable.Rows.Count > 0)
                labelsta.Text = "Login Successfull";

                labelsta.Text = "Wrong Username/Password";
        catch (Exception ex)
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Oops!! some following error occured sorry : " + ex.Message.ToString() + "');", true);        

Asp.Net VB code

Asp.Net VB source code to make simple Login page or login htmlform and check for some user auth liveuname and password

   <asp:Button ID="login_btn" runat="server" Text="Login"
            onclick="userLogin_sub" />
   <asp:Button ID="login_btn" runat="server" Text="Login" />

In the source code behind file Like as a some extentions( .aspx.vb) write the simple source code on simple Login Button’s click event as:

First of all include the following some namespaces

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

And Then write some the code as:

Read Also:  Laravel 5.8 active menu item using request

Protected Sub userLogin_sub(sender As Object, e As System.EventArgs) Handles login_btn.Click
        Dim dtable As New DataTable()
        Dim sqladpl As New SqlDataAdapter()
            Dim dbcon As New SqlConnection(ConfigurationManager.ConnectionStrings("conStr").ConnectionString)
            Dim live_cmd As New SqlCommand("simple_user_Login_check", dbcon)
            live_cmd.CommandType = CommandType.StoredProcedure
            live_cmd.Parameters.AddWithValue("@liveuname", liveUname.Text.Trim())
            live_cmd.Parameters.AddWithValue("@livepass", livepass_txt.Text.Trim())
            sqladpl.SelectCommand = live_cmd
            If dtable.Rows.Count > 0 Then
                labelsta.Text = "Good Luck Login Successfull"
                'Or in show messagebox using  ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Login Successfull');", true);
                'Or write using Response.Write("Login Successfull");
                'Or redirect using Response.Redirect("Mypanel.aspx");
                labelsta.Text = "Sorry Wrong Username/Password"
                'Or show in messagebox usingScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Sorry Wrong Username/Password');", true);
                'Or write using Response.Write("Sorry Wrong Username/Password"); 
            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Oops!! Sorry  following error occured : " & ex.Message.ToString() & "');", True)
            ' Response.Write("Oops!! Sorry following error occured: " +ex.Message.ToString());           
        End Try
    End Sub

You are Most welcome in my youtube Channel Please shubscibe my channel. and give me feedBackMore Details……
Angularjs Example


I hope you have Got What is login and registration form in with database And how it works.I would Like to have FeaeBack From My Blog( readers.Your Valuable FeedBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *