simple login screen check with database if username and password are correct in the database.
if username typed and password does not type show message please type your username.
if password typed and username does not type show message please type your password.
check username and password must match with the data base.what i typed username and password in database.
Loading
Satyapriya NayakPosted Feb 20, 2012, 11:16 PM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="login_using_parameter._Default" %>
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_using_parameter
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;
protected void btn_login_Click(object sender, EventArgs e)
{
object obj = null;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select count(*) from login where UserName=@UserName and Password =@Password";
com = new SqlCommand(str, con);
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@UserName", TextBox_user_name.Text);
com.Parameters.AddWithValue("@Password", TextBox_password.Text);
obj = com.ExecuteScalar();
if ((int)(obj) != 0)
{
lb1.Text = "WELLCOME :: " + TextBox_user_name.Text;
}
else
{
lb1.Text = "invalid user name and password";
}
con.Close();
}
}
}
Thanks
Pramod Kumar NandagiriPosted Feb 20, 2012, 1:01 PM
in source code page:
In Codebehind page
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (ValidateUser(txtusername.Text, txtpassword.Text))
{
Response.Redirect("Home.aspx");
}
else
{
Response.Write(@"Invalid User/Password");
}
}
private bool ValidateUser(string username, string pwd)
{
string strsql = "select AdminName from Admin where AdminName='" + txtusername.Text + "' and AdminPwd='" + txtpassword.Text + "'";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand(strsql, con);
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return (dr.Read());
/// go to database with username and password get true false
}
Please don't forget to mark the thread as "Accepted Answer" if it helps you