Error in creating stored procedure

Posted by Klbaiju under Sql Server on 3/26/2014 | Points: 10 | Views : 352 | Status : [Member] | Replies : 1
Hi,

I want to write a stored procedure for login

a user can use either the mobileno or email as username.

a pssword field also there i want to write a stored procedure for that

below is the code for login .how to write stored procedure

SqlCommand cmdmob = new SqlCommand("select * from registration where mobile=@mobile ", con);
cmdmob.Parameters.AddWithValue("@mobile", txtuname.Text);
DataTable dtmob = new DataTable();
SqlDataAdapter damob = new SqlDataAdapter(cmdmob);
damob.Fill(dtmob);
if (dtmob.Rows.Count > 0)
{
string mobile = dtmob.Rows[0]["mobile"].ToString();
string pword = dtmob.Rows[0]["pword"].ToString();
bool flagmob = Helper.VerifyHash(txtpword.Text, "SHA512", pword);
if (mobile == txtuname.Text && flagmob == true)
{
lbltext.Text = "Success";
}
}
else
{

SqlCommand cmdmail = new SqlCommand("select * from registration where email=@email ", con);
cmdmail.Parameters.AddWithValue("@email", txtuname.Text);
DataTable dtmail = new DataTable();
SqlDataAdapter damail = new SqlDataAdapter(cmdmail);
damail.Fill(dtmail);
string email = dtmail.Rows[0]["email"].ToString();
string pwordmail = dtmail.Rows[0]["pword"].ToString();
bool flagmail = Helper.VerifyHash(txtpword.Text, "SHA512", pwordmail);
if (email == txtuname.Text && flagmail == true)
{
lbltext.Text = "Success";
Response.Redirect("~/admin/Welcome.aspx");
}
}




Responses

Posted by: Mahesh_Chs on: 3/26/2014 [Member] Starter | Points: 25

Up
0
Down
Hi
You can write the storedprocedure like below

create procedure loginpro(
@mobilenum VARCHAR(50) =NULL,
@email VARCHAR(50)=NULL,
@password VARCHAR(50)
)
AS
BEGIN
SELECT COUNT(*) FROM LOGIN WHERE (mobile=@mobilenum AND pwd=@password)
OR (email=@email AND pwd=@password)
END


here you will get number of users with particular username or mobile number based on that you can redirect to login page. and you can give mobilenum and email as nullble types


Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response