Sample user login form
yah i am using visual studio 2010 C#.net and ms sql server 2008 .please give a sample code to develope the user login form and progress bar . please give a good solution. because i want to become a software engineer.....
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Feb 13, 2013, 12:17 PM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Login_Form_in_Csharp_Using_ProgressBar
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void btnlogin_Click(object sender, EventArgs e)
{
if (txtusername.Text == "" || txtpassword.Text == "")
{
MessageBox.Show("Please enter User ID or Password");
txtusername.Text = "";
txtpassword.Text = "";
}
else
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select count(*) from login where userid='" + txtusername.Text.Trim() + "' and password='" + txtpassword.Text.Trim() + "'";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "login");
long x;
x = Convert.ToInt64(com.ExecuteScalar());
if (x == 1)
{
int y = 0;
progressBar1.Visible = true;
progressBar1.Minimum = 1;
progressBar1.Maximum = 100000;
progressBar1.Value = 1;
progressBar1.Step = 1;
for (y = 1; y <= 100000; y++)
{
progressBar1.PerformStep();
}
Form2 f1 = new Form2();
f1.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid User ID or Password! Try Again!");
txtusername.Text = "";
txtpassword.Text = "";
}
con.Close();
}
}
}
}
Satyapriya NayakPosted Feb 13, 2013, 12:15 PM
Stored Procedure
CREATE procedure login_pro
(
@UserName varchar(50),
@Password varchar(50)
)
as
declare @status int
if exists(select * from Login where UserName=@UserName and Password=@Password)
set @status=1
else
set @status=0
select @status
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Login_Page_Using_Stored_Procedure._Default" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Pagetitle>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Name" Font-Bold="True"
Width="100px" BackColor="#FFFF66" ForeColor="#FF3300">asp:Label>
<asp:TextBox ID="TextBox_user_name" runat="server" ForeColor="#993300" Width="100px">asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox_user_name" ErrorMessage="Please enter username">asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label2" runat="server" Text="Password" Font-Bold="True"
Width="100px" BackColor="#FFFF66" ForeColor="#FF3300">asp:Label>
<asp:TextBox ID="TextBox_password" runat="server" ForeColor="#CC6600"
TextMode="Password" Width="100px">asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox_password" ErrorMessage="Please enter password">asp:RequiredFieldValidator>
<br />
<asp:Button ID="btn_login" runat="server" Text="Login" Font-Bold="True"
BackColor="#CCFF99" onclick="btn_login_Click" /><br />
<asp:Label ID="lblmessage" runat="server" Font-Bold="True" ForeColor="#FF3300">asp:Label><br />
div>
form>
body>
html>
Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Login_Page_Using_Stored_Procedure
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlParameter UserName, Password;
protected void btn_login_Click(object sender, EventArgs e)
{
UserName = new SqlParameter();
Password = new SqlParameter();
SqlConnection con = new SqlConnection(strConnString);
com=new SqlCommand();
com.Connection = con;
con.Open();
Session["UserName"] = TextBox_user_name.Text;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "login_pro";
UserName.SqlDbType = SqlDbType.VarChar;
UserName.Size = 50;
UserName.ParameterName = "@UserName";
UserName.Value = TextBox_user_name.Text.ToString();
UserName.Direction = ParameterDirection.Input;
Password.SqlDbType = SqlDbType.VarChar;
Password.Size = 50;
Password.ParameterName = "@Password";
Password.Value = TextBox_password.Text.ToString();
Password.Direction = ParameterDirection.Input;
com.Parameters.Add(UserName);
com.Parameters.Add(Password);
int status;
status = Convert.ToInt16(com.ExecuteScalar());
if (status == 1)
{
Response.Redirect("Welcome.aspx");
}
else
{
lblmessage.Text = "Invalid UserName and Password...";
}
con.Close();
}
}
}
Welcome.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="Login_Page_Using_Stored_Procedure.Welcome" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Pagetitle>
head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lb1" runat="server" Font-Bold="True" ForeColor="#FF3300">asp:Label><br />
div>
form>
body>
html>
Welcome.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Login_Page_Using_Stored_Procedure
{
public partial class Welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lb1.Text = "WELLCOME :: " + Session["UserName"];
}
}
}