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
>>>>>>>>>>>>>>>>>
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
<connectionStrings>
<add name="connection" connectionString="Data Source=ANK\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Here's sql code
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(@AccountLocked=1)
Begin
Select 1 as AccountLocked, 0 as Authenticated, 0 as RetryAttempts
End
Else
Begin
Select @Count = Count(UserName) from tblUsers
Where [UserName] = @UserName and [Password]=@Password
if(@Count=1)
Begin
Update tblUsers set RetryAttempts=0
Where UserName = @UserName
Select 0 as AccountLocked, 1 as Authenticated, 0 as RetryAttempts
End
Else
Begin
Select @RetryCount =IsNull(RetryAttempts,0)
from tblUsers
Where UserName = @UserName
Set @RetryCount = @RetryCount +1
if(@RetryCount<=3)
Begin
Update tblUsers set RetryAttempts = @RetryCount
where UserName = @UserName
Set @RetryCount = @RetryCount +1
if(@RetryCount <=3)
Begin
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?