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 7953913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:16:09+00:00 2026-06-04T03:16:09+00:00

I am requiring that the user’s current password cannot match the last five used

  • 0

I am requiring that the user’s current password cannot match the last five used passwords. The expired passwords will be stored in a table similar to this.

################################################################
#                             table_A                          #
################################################################
# id #     label    # attr_string #    attr_datetime    # u_id #
################################################################
#  1 # expired_pass #  some_hash  # YYYY-MM-DD HH:MM:SS #  1   #
#  2 # expired_pass #  some_hash  # YYYY-MM-DD HH:MM:SS #  1   #
#  3 # expired_pass #  some_hash  # YYYY-MM-DD HH:MM:SS #  1   #
#  4 # expired_pass #  some_hash  # YYYY-MM-DD HH:MM:SS #  1   #
#  5 # expired_pass #  some_hash  # YYYY-MM-DD HH:MM:SS #  1   #
################################################################

Now I am wanting a trigger that upon input checks if there are >= 5 expired passwords already stored if so then remove the oldest password. This is what I have come up with so far.

DELIMITER //
    CREATE TRIGGER removePass AFTER INSERT ON `user_attributes`(
        SET @user_id := SELECT u_id FROM `user_attributes` WHERE id = LAST_INSERT_ID()//
        SET @num := SELECT COUNT(id) FROM `user_attributes` WHERE u_id = @user_id AND label = 'expired_password'//
        IF @num >= 5 THEN
            DELETE FROM `user_attributes`
            WHERE id IN(
                SELECT id
                FROM `user_attributes`
                WHERE u_id = @user_id
                AND label = 'expired_pass'
                ORDER BY attr_datetime DESC
                LIMIT 1

            )
        END IF
    )//
DELIMITER ;
  • 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-06-04T03:16:11+00:00Added an answer on June 4, 2026 at 3:16 am

    You can avoid using attr_datetime and rely on ids:

    DELETE FROM `user_attributes`
                WHERE id = (
                    SELECT MIN(id)
                    FROM `user_attributes`
                    WHERE u_id = @user_id
                    AND label = 'expired_pass'
                )
    

    P.S. Thank to @sixlettervariables for the comment and Brock for advice.

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

Sidebar

Related Questions

I need to create a python module that will be installed on end-user machines.
I'm working on an intermediary form that will gather some data from the user
I am writing an application that is requiring me to do a DNS lookup
I've created a Java class that connects to an IIS website requiring NTLM authentication.
I am trying to find a solution that will resolve a recurring deadlock situation
i have some customers with a particular address that the user is searching for:
As a seasoned Spring user I was assuming that Spring Integration would make the
I have a batch file that I want to improve. Instead of requiring a
I have a library that I distribute using maven 2. The typical user of
What happens is that if a user clicks on the 'Get Session Id' button.

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.