Completely Free .NET word API

Resources » Code Snippets » ASP.NET WebForms

code for login using C#

Updated: Category: ASP.NET WebForms
Author: Member Level: GoldPoints: 10

Code for login validation:
create table:
Table Name: login details
field: login, Datatype: Text
password, DataType: Text.

Code is design in such a way that every user are not allow to visit evert page.
suppose if u r not a administrator then u will not able to see the page newentry.aspx, u will redirect on default.aspx.

protected void logins(string username, string password)
string s;
OleDbConnection cn = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0;" + @"Data Source= D:\rajni\App_Data\rajni.mdb");
OleDbCommand cmd = new OleDbCommand("SELECT password from logindetails where login = @id;", cn);
OleDbParameter par = cmd.Parameters.Add("@id", OleDbType.VarChar);
par.Value = username;
DataSet ds = new DataSet("details");
OleDbDataAdapter details = new OleDbDataAdapter();
details.SelectCommand = cmd;
string dbpassword = null;
string givenpassword = TextBox2.Text;
DataRow dr = ds.Tables[0].Rows[0];
dbpassword = (string)dr["password"];
if (dbpassword == givenpassword)
Session["username"] = TextBox1.Text;
s = Convert.ToString(Session["username"]);
Session["admin"] = s;
if (s == "administrator")
Label1.Text = "Invalid password";
Label1.Text = "Invalid login and password";
TextBox1.Text = "";
TextBox2.Text = "";


Did you like this resource? Share it with your friends and show your love!

Responses to "code for login using C#"

No responses found. Be the first to respond...


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Phagu Mahato
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India