如果他输入错误的用户凭据超过5倍,如何阻止用户帐户(如何阻止输入错误用户凭据的当前用户) [英] How to block user account(how to block current user who is entering wrong user credentials) , if he enter more than 5 times wrong user credentials

查看:99
本文介绍了如果他输入错误的用户凭据超过5倍,如何阻止用户帐户(如何阻止输入错误用户凭据的当前用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

how to user block if user enter five time wrong password and what is logic in SQL Server of block user for 30 minute if 5 time enter invalid password. and how to set this time 30 minute to 0 minute after 30 minute. I am trying in sql server







CREATE PROCEDURE Usp_CheckLoginDetail
-- Add the parameters for the stored procedure here
@Userid nvarchar(100),
@Password varchar(500),
@ResponseMsg int OUTPUT
AS
BEGIN
  -- SET NOCOUNT ON added to prevent extra result sets from
  -- interfering with SELECT statements.
  SET NOCOUNT ON;
 
  BEGIN TRY

    IF EXISTS (SELECT Count(*) FROM TM_UserDetails WHERE UserId = @UserId) --Check User is Valid or not
    BEGIN
      IF EXISTS (SELECT Count(*) FROM TM_UserDetails WHERE UserId = @UserId AND [Password] = @Password and FirstLoginStatus=0 and FreezeStatus = 0 and BlockedStatus = 0)--Check User id and password is Valid 
      BEGIN
        SELECT          *
        FROM TM_UserDetails 
      END
      ELSE if EXISTS(SELECT Count(*) FROM TM_UserDetails WHERE UserId = @UserId AND [Password] = @Password and FirstLoginStatus=1 and FreezeStatus = 1 and BlockedStatus = 0)--Check User id and password is Valid but user is doing first time login
      BEGIN
        SET @ResponseMsg = 2  -- First Time User
		--Code Will be write later
      END
	  ELSE ---If User Enter Wrong Password code block
      BEGIN
	  declare @Couter int = 1
	  declare @Count int
	  declare @BlockCount int,@BlockedDte datetime,@BlockStatus bit 
	  select  @BlockCount = ISNULL(BlockCount,0) , @BlockedDte = ISNULL(BlockedDate,getdate()) ,@BlockStatus = ISNULL(BlockedStatus,0) from TM_UserDetails where UserId = @Userid
	  if @BlockCount < 5
	  begin
	  set @BlockCount = @BlockCount + 1
	  update TM_UserDetails set BlockCount = @BlockCount , BlockedStatus = 1 , BlockedDate = GETDATE() where  UserId = @Userid
	  End
	  else if @BlockCount = 5
	  begin
	  SET @ResponseMsg = 5 -- Blocked User
	  end

      END
    END
    ELSE
    BEGIN
      SET @ResponseMsg = 1  -- Invalid User
    END
  END TRY
  BEGIN CATCH
    SET @ResponseMsg = 3  -- Invalid User
  END CATCH


END

GO





我尝试了什么:



我在sql程序中试过这个解决方案但问题是我需要花时间在
$之间b $ b两个请求检查用户ID和密码以刷新数据库中的计数器值。因为

用户输入连续5次错误的用户ID和密码然后它将被阻止30分钟。



What I have tried:

I tried this solution in sql Procedure but problem is that what i will take time between
two request to check user id and password to refresh counter value in database. because
user enter continues 5 times wrong user id and password then it will be block 30 minute.

推荐答案

当你发现用户已输入5次错误的用户密码你可以添加一列,因为我建议并添加datetime.now + 30 min.we调用blockTime ..并且没有尝试设置为0.

就像我输入错误用户名和密码4次。在上午9:30我输入了错误的用户名和密码。 DatetimNow + 30分钟= 10:00 AM。所以用户在上午10:00阻止..

并将NoOfTimes设为零。



在9:30到10:00 am他正试图证明他当时是封锁的。在每次验证时,用户检查日期时间现在都小于阻止时间。



10:00 am之后用户尝试访问然后删除阻止时间作为用户正试图访问10:05和你可以进行的相同过程
when you find user have enter 5 times wrong user password you can add one column as i suggest and add datetime.now + 30 min.we call as blockTime .. and no of try set to be 0.
like i am typeing wrong user name and password 4 time . at 9:30AM i have enter wrong username and password so . DatetimNow+30 min =10:00AM . so user is block 10:00 AM..
and set NoOfTimes to be zero.

in 9:30 to 10:00 am he is trying to autheicate he is block for that time. in each time when you are authenticate user check datetime now is less than block time or not.

after 10:00 am user try to access then remove block time as user is trying to access 10:05 and same process you can carry on


将一个conunter放入authenticate表中。



喜欢

用户名|密码| NoOfTime | BlockTime |

xyz | xyz | 0 |

ABC | abc | 5 | 2:30 PM

当您尝试进行身份验证时,用户输入错误的cridenticial增加nooftime值。如果authenticate正确,则将nooftime值设置为0。

如果NoOfTime< 5

在BlockTime中设置值并将NoOfTime设置为0.




你可以通过这种方式
Put one conunter in in authenticate table.

like
UserName| Password |NoOfTime |BlockTime |
xyz | xyz |0 |
ABC | abc |5 |2:30PM

where user enter wrong cridenticial increase nooftime values when you Are trying to authenticate .. if authenticate is proper then set nooftime values to 0.
if NoOfTime<5
Set Value in BlockTime and set NoOfTime to 0.


in this way you can do it.


这篇关于如果他输入错误的用户凭据超过5倍,如何阻止用户帐户(如何阻止输入错误用户凭据的当前用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆