Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:40:59+00:00 2026-05-26T23:40:59+00:00

This stored procedure doesn’t update the column FailedLoginAttempts if the conditions are true. Can

  • 0

This stored procedure doesn’t update the column FailedLoginAttempts if the conditions are true. Can anyone tell me what might be wrong with this?

ALTER PROCEDURE UpdateFailedLoginAttempts
    (
        @username varchar(100),
        @failureType varchar(100),
        @maxInvalidPasswordAttempts int
    )
AS
BEGIN

    DECLARE @failureCount int

    IF (@failureType='Password') BEGIN
        SELECT @failureCount=FailedLoginAttempts FROM Users
        WHERE Username=@username

        UPDATE Users SET FailedLoginAttempts=@failureCount+1 WHERE Username=@username    

        IF(@failureCount >= @maxInvalidPasswordAttempts) BEGIN
            UPDATE Users SET IsUserLocked = 1 WHERE Username=@username
        END 
    END
END

What i’m trying to achieve is if the failureType is Password, then it should SET @failureCount equal to FailedLoginAttempts and then update FailedLoginAttempts to @failureCount + 1 (to increase the amount of failed attempts) and then check if @failureCount is greater than or equal to @maxInvalidPasswordAttempts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:40:59+00:00Added an answer on May 26, 2026 at 11:40 pm

    One thing I am noticing is that you:

    • set @failureCount = FailedLoginAttempts

    • update FailedLoginAttempts = @failureCount + 1

    • check @failureCount >= @maxInvalidPasswordAttempts

    This is not checking against the updated FailedLoginAttempts value, so you will likely have to fail one additional time than you expect before an account is locked.

    Since you have to run an update anyway, you could consider this route:

    UPDATE u
    SET u.IsUserLocked =
       CASE
          WHEN (FailedLoginAttempts + 1) >= @maxInvalidPasswordAttempts THEN 1
          ELSE u.IsUserLocked
       END
       , u.FailedLoginAttempts = u.FailedLoginAttempts + 1
    FROM Users AS u
    WHERE u.Username = @username
    

    It removes the need to make multiple statements, or the variable @failureCount

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please point out what im doing wrong with this Stored Procedure please.
I'm using adodb5 to call this stored procedure but MySQL doesn't understand $sealID is
This stored procedure doesn't work. It just returns 0 rows. I've checked the SQL
I have a stored procedure and if the stored procedure does this: SELECT 0
Does anybody know how to do this syntax below in mysql? Without Stored Procedure,
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,
Well I have this MySQL stored procedure that I wrote and if I run
This code involves a recursive Stored Procedure call and a not so great method
I have a mysql stored procedure from this ( google book ), and one
I've got a mySql stored procedure that looks like this-- delimiter | create procedure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.