can some one please help me with code for the following :
create a method called VerifyUser which willcontain 2 arguments( Account number & pin) as input from the application. verify the supplied account number and pin corresponds with the initialized account number and pin which are both initialized as string and equal to "111". if they correspond display "successfully logged on" and if the don't display "incorrect" this method must also return a true or false.
Loading
Munir ShaikhPosted Aug 16, 2007, 8:40 AM
Here is sample code which check for user name and password in the database table, if both of login credential matches then it will return 1 else 0, so modify your code as you want and enjoy, even if you want some return values then you can use ExecuteScalar() or return dataset method. Here it is
public int AuthenticateUser(string userName, string userPassword)
{
int retVal = 0;
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string strSql = "SELECT userId, userName, userPassword FROM Tbl_User WHERE (userName = '"+ userName +"') AND (userPassword = '"+ userPassword +"');
SqlCommand sqlcomd = new SqlCommand(strSql,sqlcon);
try
{
sqlcon.Open();
if (dtstAuthenticate.Tables[0].Rows.Count >0 )
{
retVal = sqlcomd.ExecuteNonQuery();
}
}
catch
{
}
finally
{
sqlcon.close();
}
return retVal;
}
Note ConnectionString is stored in web.config
Enjoy!
>>Munnamax