tag:blogger.com,1999:blog-6082652835152798567.post4724849338051391915..comments2024-03-28T21:41:58.974-07:00Comments on Sql server, .net and c# video tutorial: Forms authentication and locking user accounts - Part 93Unknownnoreply@blogger.comBlogger6125tag:blogger.com,1999:blog-6082652835152798567.post-33878167208126946712018-06-23T09:08:53.463-07:002018-06-23T09:08:53.463-07:00initial check needed as in
alter proc spAunthenti...initial check needed as in<br /><br />alter proc spAunthenticateUser<br />@UserName nvarchar(25),<br />@Password nvarchar(15)<br />as<br />Begin<br /> Declare @AccountLocked bit<br /> Declare @Count int<br /> Declare @RetryCount int<br /> <br /> select @count = count(UserName)<br /> from tblUsers<br /><br /> if(@Count = 0 )<br /> begin<br /> select -1 as ReturnValue<br /> end<br /> else<br /> begin<br /> Select @AccountLocked = IsLocked<br /> from tblUsers where UserName = @UserName<br /> <br /> --If the account is already locked<br /> if(@AccountLocked = 1)<br /> Begin<br /> Select 1 as AccountLocked, 0 as Authenticated, 0 as RetryAttempts<br /> End<br /> Else<br /> Begin<br /> -- Check if the username and password match<br /> Select @Count = COUNT(UserName) from tblUsers<br /> where [UserName] = @UserName and [Password] = @Password<br /><br />Rest as above by VenkatPrashant Channehttps://www.blogger.com/profile/07575600164942536883noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-83716196462557338222016-07-31T01:16:51.408-07:002016-07-31T01:16:51.408-07:00I can register successfully but when i am trying t...I can register successfully but when i am trying to login with same username and password even for first time it not login<br />it lock the account why<br />As i done same code<br /><br />Rakesh Shindehttps://www.blogger.com/profile/09716056366547596649noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-51654682754195424252016-03-03T07:22:38.025-08:002016-03-03T07:22:38.025-08:00create proc spAuthenticateUser
@UserName nvarcha...create proc spAuthenticateUser <br />@UserName nvarchar(100), <br />@Password nvarchar(200) <br />as <br />Begin <br /> Declare @AccountLocked bit <br /> Declare @Count int <br /> Declare @RetryCount int <br /> Select @count=count(username) from tblusers where username=@UserName<br />If(@count=0)<br />Begin<br /> Select 0 as AccountLocked, 0 as Authenticated, 0 as RetryAttempts <br />End<br />Else<br />Begin<br /> Select @AccountLocked = isnull(IsLocked,0) <br /> from tblUsers where UserName = @UserName <br /> <br /> <br /> if(@AccountLocked = 1) <br /> Begin <br /> Select 1 as AccountLocked, 0 as Authenticated, 0 as RetryAttempts <br /> End <br /> Else <br /> Begin <br /> <br /> Select @Count = COUNT(UserName) from tblUsers <br /> where [UserName] = @UserName and [Password] = @Password <br /> <br /> <br /> if(@Count = 1) <br /> Begin <br /> <br /> Update tblUsers set RetryAttempts = 0 <br /> where UserName = @UserName <br /> <br /> Select 0 as AccountLocked, 1 as Authenticated, 0 as RetryAttempts <br /> End <br /> Else <br /> Begin <br /> <br /> Select @RetryCount = IsNULL(RetryAttempts, 0) <br /> from tblUsers <br /> where UserName = @UserName <br /> <br /> Set @RetryCount = @RetryCount + 1 <br /> <br /> if(@RetryCount <= 3) <br /> Begin <br /> <br /> Update tblUsers set RetryAttempts = @RetryCount <br /> where UserName = @UserName <br /> <br /> Select 0 as AccountLocked, 0 as Authenticated, @RetryCount as RetryAttempts <br /> End <br /> Else <br /> Begin <br /> <br /> Update tblUsers set RetryAttempts = @RetryCount, <br /> IsLocked = 1, LockedDateTime = GETDATE() <br /> where UserName = @UserName <br /> <br /> Select 1 as AccountLocked, 0 as Authenticated, 0 as RetryAttempts <br /> End <br /> End <br /> End <br />End<br />End<br />Anonymoushttps://www.blogger.com/profile/06674047307868064501noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-26748821773449111052015-05-16T05:43:27.169-07:002015-05-16T05:43:27.169-07:00Please ,how i enter an invalid username and passwo...Please ,how i enter an invalid username and password <br />lblmessage text become "Account locked. Please contact administrator<br />"<br />but i want to make it "Username does not exist"?mohamed elnenohttps://www.blogger.com/profile/16243344769086503006noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-2072739403928532132015-01-28T00:40:16.909-08:002015-01-28T00:40:16.909-08:00In this case the following message will appear:
&...In this case the following message will appear:<br /><br />"Account locked. Please contact administrator"<br /><br />The reason is because<br />Select @AccountLocked = IsLocked<br />from tblUsers where UserName = @UserName<br />does not match in this case.<br /><br />You can alter the procedure <br />by asking first:<br /><br />select @count = COUNT(UserName)<br /> from tblUsers<br /> where Username = @UserName<br /><br /> if (@count = 0)<br /> Begin<br /> Select 0 as AccountLocked, 0 as Authenticated, 0 as RetryAttempts<br /> End<br /> else<br /> .... (the rest of procedure)<br /><br />In the Programm login.aspx.cs <br />you add an else-condition:<br /><br />if (Convert.ToBoolean(rdr["AccountLocked"]))<br />{<br /> ...<br /> }<br />else<br />{<br /> lblMessage.Text = "User does not exist! Please register first!";<br />}<br /><br />Kind regards Gerhard Wittenoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-543281253896583392014-08-22T00:53:42.596-07:002014-08-22T00:53:42.596-07:00IF THE USER DOES NOT HAVE ACCOUNT AND ENTERED NA...IF THE USER DOES NOT HAVE ACCOUNT AND ENTERED NAME, WHICH DOES NOT EXIST IN DATABASE THEN .. WHAT WILL HAPPEN ? <br /><br />( wasim )Anonymousnoreply@blogger.com