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

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

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

In this post we will show you Best way to implement login and registration form in asp.net with database, hear for registration form in asp.net 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 asp.net 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.

HOW TO CREATE SIMPLE LOGIN PAGE-FORM AND CHECK USERNAME,PASSWORD using ASP.NET

STORED PROCEDURE AND SQL SERVER DATABASE

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)
AS
BEGIN
                select * from table_login
                where uname COLLATE Latin1_general_CS_AS=@liveuname
                and [Password] COLLATE Latin1_general_CS_AS=@livepass
END
In the web.config file create the connection string to connect the asp.net web application with the sql server database as.
  
    
  

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:

 
Login example in asp.net
User Name: *
Password: *
 
 

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.

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();    
        try
        {
            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;          
            sqladpl.Fill(dtable);
            live_cmd.Dispose();
            if (dtable.Rows.Count > 0)
            {
                labelsta.Text = "Login Successfull";

            }
            else
            {
                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);        
        }
        finally
        {
            dtable.Clear();
            dtable.Dispose();
            sqladpl.Dispose();         
        }     
    }

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

   
with 
   

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:

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()
        Try
            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
            sqladpl.Fill(dtable)
            live_cmd.Dispose()
            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");
            Else
                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());           
        Finally
            dtable.Clear()
            dtable.Dispose()
            sqladpl.Dispose()
        End Try
    End Sub

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

Example

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

Leave a Comment