Dear Sir,
How to check user name ,password validation name in database send me coding
details
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 12, 2012, 6:17 PM EST
It is a web or windows app.
If windows
Try this...
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();
}
}
}
}
If web...
http://www.c-sharpcorner.com/uploadfile/abhikumarvatsa/simple-login-project-in-Asp-Net/default.aspx
Thanks
Dinkar ChavhanRank #1,132 · 1.6K reputationPosted Jan 12, 2012, 6:20 PM EST
create proc SP_User(@username varchar(50),@password varchar(50))
as
begin
select * from [tblname] where username=@username and password=@password
end
Mukesh KumarRank #615 · 3.9K reputationPosted Jan 12, 2012, 7:23 PM EST
aspx.cs file
//***********//
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.Text;
public partial class Login
{
StringBuilder onLoadMethods = new StringBuilder(150);
StringBuilder sb = new StringBuilder(150);
string userName;
void Page_PreRender(object sender, EventArgs e)
{
sb.Append(" \n");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "onLoadMsg", sb.ToString());
}
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["myCookie"] != null)
{
HttpCookie cookie = Request.Cookies.Get("myCookie");
txtLogin.Attributes.Add("value", cookie.Values["userName"].ToString());
if (Convert.ToBoolean(cookie.Values["Remember"]))
RememberMe.Checked = true;
}
if (!IsPostBack)
{
txtLogin.Attributes.Add("onKeyPress", "doClick('" + lbLogin.ClientID + "',event)");
txtPassword.Attributes.Add("onKeyPress", "doClick('" + lbLogin.ClientID + "',event)");
}
}
protected void lbLogin_Click(object sender, EventArgs e)
{
if (CheckLoginAndPassword(txtLogin.Text.Trim(), txtPassword.Text.Trim()))
{
if (!string.IsNullOrEmpty(userName))
{
if (RememberMe.Checked)
{
HttpCookie myCookie = new HttpCookie("myCookie");
Response.Cookies.Remove("myCookie");
Response.Cookies.Add(myCookie);
myCookie.Values.Add("userName", userName);
myCookie.Values.Add("Remember", RememberMe.Checked.ToString());
DateTime dtExpiry = DateTime.Now.AddDays(15); //you can add years and months too here
Response.Cookies["myCookie"].Expires = dtExpiry;
}
else
{
DateTime dtExpiry = DateTime.Now.AddDays(-1); //you can add years and months too here
Response.Cookies["myCookie"].Expires = dtExpiry;
}
FormsAuthentication.RedirectFromLoginPage(userName, false);
if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
Response.Redirect("Home.aspx");
else
Response.Redirect(Request.QueryString["ReturnUrl"].ToString());
}
}
else
{
onLoadMethods.Append("alert('Your login attempt was not successful. Please try again.');");
}
}
public bool CheckLoginAndPassword(string username, string password)
{
bool authenticate = false;
if (username.Contains("@")) //Email Login
{
string usern = Membership.GetUserNameByEmail(username);
if (!string.IsNullOrEmpty(usern))
{
if (Membership.ValidateUser(usern, password))
{
userName = usern;
authenticate = true;
}
else authenticate = false;
}
}
else //Standard Username & Password Login
{
userName = username;
if (Membership.ValidateUser(username, password))
authenticate = true;
else
authenticate = false;
}
return authenticate;
}
}
//***********//
aspx file
//***********//
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>