how to validate login?
how to validate in login form that username and password is not matching ?? or username not exists or password is wrong
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question.
Satyapriya NayakPosted Jul 26, 2012, 6:29 AM
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_page_Msaccess
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
string str;
object obj = null;
public Form1()
{
InitializeComponent();
}
private void btn_login_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select count(*) from login where UserName=@UserName and Password =@Password";
com = new OleDbCommand(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
Vilas GitePosted Jul 26, 2012, 4:44 AM
CONTROLS : 2 LABLE, 2 TEXTBOX, 2 BUTTONS