This Project is used to generate random passwords of a specified length which enhances password complexity and security.
1. *Libraries & Global Variables*:
- Three libraries are included: `` for input-output operations, `` for random number generation, and `` to seed the random number generator using the current time.
- An array `alphnum` contains possible characters for the password.
- `strLen` calculates the length of this array.
2. *GenRand() Function*:
- This function returns a random character from the `alphnum` array using the `rand()` function.
3. *Main Function*:
- Variables are initialized: `n` for desired password length, `c` to count numeric characters, and `s` to count special characters.
- The random number generator is seeded with the current time using `srand(time(0))`.
- The user is prompted to enter their desired password length and the input is stored in `n`.
- The entered length is then displayed.
- A label `N:` is defined. This is used for the `goto` statement for retrying password generation.
- A loop runs `n` times to generate `n` random characters. Each generated character is appended to the string `D`. During this loop:
- If the character is a digit, `c` is incremented.
- If the character is one of the special characters listed, `s` is incremented.
- After generating the password, a check is made to ensure that for passwords longer than 2 characters, there is at least one numeric and one special character. If not, the password generation is retried by jumping to the `N:` label using the `goto` statement.
- Once a valid password is generated, it's displayed to the user.
- Finally, a thank you message is displayed.
In summary, this code prompts the user for a desired password length and generates a random password of that length, ensuring the inclusion of at least one numeric and one special character for passwords longer than 2 characters.
Submitted by Abhishek Gupta (abhishekgupta02)
Download packets of source code on Coders Packet
Comments