Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making login page. Now, when i put username, password, it keeps rotating and doesnt do anything.

I started it in debug mode and saw that it doesnt loop through code inside while statement

>>>>>>>>>>>>>>>>>
C#
while(rdr.Read())
            {

                int RetryAttempts = Convert.ToInt32(rdr["RetryAttempts"]);
                if(Convert.ToBoolean(rdr["AccountLocked"]))
                {

                    Label3.Text = "Account Locked.Please Contact administration";
                }

                else if(RetryAttempts>0)
                {
                    int AttemptsLeft = (4 - RetryAttempts);
                    Label3.Text = "Invalid user name and/or password" + AttemptsLeft.ToString() + "attempts left";

                }

                else if(Convert.ToBoolean(rdr["Authenticated"]))
                {

                    FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, CheckBox1.Checked);
                    Response.Redirect("welcome.aspx");
                }


            }





When i checked, it doesnt go through code inside while loop.



Here's webconfig file

SQL
<connectionStrings>

    <add name="connection" connectionString="Data Source=ANK\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=true;" providerName="System.Data.SqlClient"/>

  </connectionStrings>



Here's sql code

SQL
Alter proc spAuthenticateUser
@UserName nvarchar(100),
@Password nvarchar(200)

as 
Begin
Declare @AccountLocked bit
Declare @Count int
Declare @RetryCount int

Select @AccountLocked=IsLocked
from tblUsers where UserName=@UserName

--if the account is already locked
             if(@AccountLocked=1)
              Begin
             Select 1 as AccountLocked, 0 as Authenticated, 0 as RetryAttempts
             End
             Else
             Begin
--check if the username and password match
Select @Count = Count(UserName) from tblUsers
Where [UserName] = @UserName and [Password]=@Password
--if match found
if(@Count=1)
Begin
--Reset RetryAttempts
Update tblUsers set RetryAttempts=0
Where UserName = @UserName
Select 0 as AccountLocked, 1 as Authenticated, 0 as RetryAttempts
End
Else
Begin
--If a match is not found

Select @RetryCount =IsNull(RetryAttempts,0)
from tblUsers
Where UserName = @UserName
Set @RetryCount = @RetryCount +1

if(@RetryCount<=3)
Begin

--if retry attempts are not completed

Update tblUsers set RetryAttempts = @RetryCount
where UserName = @UserName

Set @RetryCount = @RetryCount +1

if(@RetryCount <=3)

Begin
--if retry attempts are not completed

Update tblUsers set RetryAttempts = @RetryCount

where UserName = @UserName
Select 0 as AccountLocked, 0 as Authenticated, 0 as RetryAttempyts

End
End
End

End
End


Can someone please help me?
Posted
Comments
Sergey Alexandrovich Kryukov 22-Apr-15 12:30pm    
And where is the question? ("Can someone please help me?" does not count, of course. :-)
—SA
ankur1163 22-Apr-15 12:32pm    
I am making login page. Now, when i put username, password, and hit login.It keeps rotating and doesnt do anything.

I have checked this code in debug mode. The code inside while loop doesnt run. It entirely skips the code inside while loop.
Afzaal Ahmad Zeeshan 22-Apr-15 12:36pm    
Reply to their comment in order to let them know you have a reply for them.
ankur1163 22-Apr-15 12:35pm    
This is the image of rdr
http://postimg.org/image/u3a8b5hd9/
Richard MacCutchan 22-Apr-15 12:47pm    
Did you check if the reader actually has any content?

Put a if condition outside the while loop and check the 'HasRows' property of the reader object like 'if(rdr.HasRows)'. By doing this you will make sure that the while loop will be executed only if there are rows in reader.
 
Share this answer
 
Try
SQL
while (reader.HasRows)
{
    //Code
    reader.NextResult();
}
 
Share this answer
 
Comments
ankur1163 22-Apr-15 13:49pm    
no, it still bypass entire code in while statement. very strange

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900