Generating passwords with PHP
Jul 15th, 2008 by knutee
Last night I got the urge to make a strong password generator for this site. Don’t really know why, just inspiration I guess. However, it was getting quite late and I fell asleep after 3 lines of code. Luckily, the inspiration stayed with me, and today I got the grunt work done on the code.
I wanted the application to follow a set of generating rules, but at the same time give the user the option to choose both length and strength. This meant that the program would require:
- All alphanumeric characters
- A set of special characters
- A scale of strength, defining which characters to use
- Repeated generation until length of password is met
- Random choice of characters to use
This part is easy and straight forward, but it does contain the possibility that only a single character will be used, or that it returns a password purely based on special characters. To make the password stronger i had to make sure that the program used all of it’s options; not too much, not too little. I chose to solve this by using a selection array and define how many % of the password would be lowercase, uppercase, numbers and special characters.
The code is far from finished at this stage. It does allow me to pass a length and strength argument to the function, and based on that it does generate a password according to the rules I’ve set.
However, everything is currently hard coded and not very user friendly. I’ll keep working at it and have the tool up on this site soon. The source code will of course also be available, and a walk through will be posted in the projects section.
Update
Code and project page is finished. You can read about it here.