Improve your contact center performance. See how you can make a difference.
Watch Now
Engage and build your ICT audience with CIOL online advertising.
Know more
Let me start with doing what you do always, build an application with user management features built in it. Just to make it easier, if you are trying this out along with me, I would hard code my user database instead of building the user management screens.
Direct Hit!
USE payroll GO CREATE TABLE ApplicationUser ( UserName nvarchar(25), Password nvarchar(25) ) GO INSERT INTO ApplicationUser VALUES('Amit', 'Password4Amit') INSERT INTO ApplicationUser VALUES('Aparna', 'Password4Aparna') GO
First I have made a screen for my users to log in (see below).
Here is the code I have used to verify that the user name and password are correct.
protected void btnSubmit_Click(object sender, EventArgs e) { string strSQL = "SELECT Password FROM ApplicationUser WHERE UserName = '" + txtUserName.Text + "'"; string strConnection = "Data Source=(local); " + "Integrated Security = SSPI; Initial Catalog=payroll"; string strPassword; bool blnValidUser = false; SqlConnection conPayroll = new SqlConnection(strConnection); SqlCommand cmdUserValidate = new SqlCommand(strSQL, conPayroll); conPayroll.Open(); try { strPassword = cmdUserValidate.ExecuteScalar().ToString(); if (txtPassword.Text == strPassword) { blnValidUser = true; } } catch (NullReferenceException) { } catch (SqlException) { } if (blnValidUser) { lblMessage.Text = "Congratulations. Successfull login!"; } else { lblMessage.Text = "Login failed!"; } }
NEXT>>