locked
How to create a password generator with some validation rules? RRS feed

  • Question

  • User-353733005 posted

    I want to create a password generator method which fulfill some validation rules. I already create a generator calling random object I but I don't understand how fulfill the validation rules. Here is my validation rules:

    1. Minimal 1 upper and 1 lower case character 

    2. Minimal 1 digit in password

    3. Minimal 1 punctuation mark in a password (!@#$%^&*()-_+=)

    4. Not more than twice using the same character after each other

    5. Same character must not exist more than 3 times in password

    6. Minimal length must be 10 characters

    can anyone help me please to build this password generator method using this validation rules.

    Thanks in advance.

    Thursday, August 6, 2015 6:34 AM

Answers

  • User281315223 posted

    A naive approach to handling this might be to simply define all of your requirements as types of Regular Expressions and continually build a random string until it meets all of the requirements (at the end of each iteration, determining which requirements are lacking and adding those). However, you may want to consider checking if this has already been done for you.

    I came across this project on GitHub, which appears to be designed to do exactly what you are looking for (generating strings based on certain rules). It appears to be quite well documented and it should be able to handle most of what you need.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 6, 2015 8:36 AM
  • User-434868552 posted

    @Shibly

    KeePass has already done this for you; it's open source:  http://keepass.info/

    "KeePass, the free, open source, light-weight and easy-to-use password manager."

    http://keepass.info/download.html "<small>Source code packages, containing everything you need to build your own </small><small>KeePass.exe</small><small> and plugins (source code, resources, build scripts, ...)" can be found near the bottom of the download page.</small>

    You can read about the password options here:  http://keepass.info/help/base/pwgenerator.html 

    Example:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 6, 2015 3:23 PM

All replies

  • User281315223 posted

    A naive approach to handling this might be to simply define all of your requirements as types of Regular Expressions and continually build a random string until it meets all of the requirements (at the end of each iteration, determining which requirements are lacking and adding those). However, you may want to consider checking if this has already been done for you.

    I came across this project on GitHub, which appears to be designed to do exactly what you are looking for (generating strings based on certain rules). It appears to be quite well documented and it should be able to handle most of what you need.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 6, 2015 8:36 AM
  • User-434868552 posted

    @Shibly

    KeePass has already done this for you; it's open source:  http://keepass.info/

    "KeePass, the free, open source, light-weight and easy-to-use password manager."

    http://keepass.info/download.html "<small>Source code packages, containing everything you need to build your own </small><small>KeePass.exe</small><small> and plugins (source code, resources, build scripts, ...)" can be found near the bottom of the download page.</small>

    You can read about the password options here:  http://keepass.info/help/base/pwgenerator.html 

    Example:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 6, 2015 3:23 PM