Login Page Problem with ireturnvalue always zero

Posted by Suneel161 under Regular Expressions on 3/4/2010 | Views : 1245 | Status : [Member] | Replies : 3
Hi all, I have problem with getting the ireturnvalue always getting "Zero" whenever giving correct username passworrd also...
what is the problem in below code pls anybody help me!!!

Stored Procedure
--------------------
CREATE PROCEDURE loginuser1  
@uid varchar(15),
@password varchar(15)
AS
select uid,password from Register
where uid= @uid and password=@password
--INSERT INTO Categories (CategoryName) VALUES(@CategoryName)
RETURN @@ROWCOUNT

---------------------------------------------------------------------------------------------

code
---------

protected void btnLogin_Click(object sender, EventArgs e)
{
switch (UserLogin(txtUsername.Text, txtPassword.Text))
{
case 1:
Session.Abandon();
Login();
break;
case 2:
litUserData.Text = "Bad Password";
break;
case 3:
litUserData.Text = "Unknown User";
break;

default:
litUserData.Text = "Wrong Username/Password";
break;
}

public int UserLogin(string strUsername, string strPassword)
{
int iReturnValue = 0;

string connStr = ConfigurationManager.ConnectionStrings["ConnString"].ToString();
//string strconnection = "Server=MSSINET ;database=test;uid=sa;pwd=sa;";
//SqlConnection con1 = new SqlConnection(strconnection);
SqlConnection con1 = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("mohanloginuser1", con1);
cmd.CommandType = CommandType.StoredProcedure;



cmd.Parameters.Add("@uid", strUsername);
// cmd.Parameters.Add("@password", strPassword);
// cmd.Parameters.Add("@ROWCOUNT", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;

cmd.Parameters.Add("@ROWCOUNT", SqlDbType.Int);
cmd.Parameters["@ROWCOUNT"].Direction = ParameterDirection.ReturnValue;

//cmd.Parameters.Add("@Identity", SqlDbType.Int, 0, "SID") = ParameterDirection.Output;

MD5CryptoServiceProvider md5Haser = new MD5CryptoServiceProvider();
Byte[] hasedbyte;
UTF8Encoding encoder = new UTF8Encoding();

hasedbyte=md5Haser.ComputeHash(encoder.GetBytes(txtPassword.Text));

SqlParameter parampwd=new SqlParameter();
parampwd = new SqlParameter("@password", SqlDbType.Binary, 16);
parampwd.Value = hasedbyte;
cmd.Parameters.Add(parampwd);
/*Dim md5Hasher as New MD5CryptoServiceProvider()

Dim hashedDataBytes as Byte()
Dim encoder as New UTF8Encoding()

hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(txtPwd.Text))

Dim paramPwd as SqlParameter
paramPwd = New SqlParameter("@Password", SqlDbType.Binary, 16)
paramPwd.Value = hashedDataBytes
objCmd.Parameters.Add(paramPwd)*/


con1.Open();
cmd.ExecuteNonQuery();
iReturnValue = System.Convert.ToInt32(cmd.Parameters["@ROWCOUNT"].Value.ToString());
//Console.WriteLine("@Identity: {0}", cmd.Parameters["@Identity"].Value);
con1.Close();
return iReturnValue;
}





Responses

Posted by: Vuyiswamb on: 3/4/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
You are Breaking Rule number two of the Forum. Please Read this First before you post
http://www.dotnetfunda.com/forums/thread1503-forum-guidelines-before-posting-or-answering-a-question.aspx

it is difficult to read this kind of post and it is difficult for users users to help you on your Problem.

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: Abhi2434 on: 3/4/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Check if you run the same query in sql console, what is the return value.

Just execute the Stored Proc with uid and encrypted password and check.
It must return more than 0 if it matches exactly.




www.abhisheksur.com

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

Posted by: Vuyiswamb on: 3/4/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day

You are Creating a login Functionality and the approach you have used is failing you. Look at how its done here
http://www.daniweb.com/forums/thread138587.html

Thank you for posting at dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

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

Login to post response