Recently I had a client ask for a program that did a task and was also password protected. Once the application was created the client asked for a simple password to be applied to the application to keep unauthorized users from accessing the application.
I have always been one to program myself out of the loop. That is, I did not want the client to call me every time there was a turnover at the company or they wanted the password changed. With that in mind and the fact we were not trying to secure missile codes, I implemented password structure that would change everyday and could be as simple or complex as the user required. Based on the current date (i.e. 15th), the password would be a mathematical formula whose result equaled 15. So the user was free to make the password as simple (within reason) or complex as they required. Using 15 as an example the password could be 3*5 or 17-2 or even ((2-1)*(10-5))*3. The next day that password would not work and would be based off 16.
The C# code is below:
In the application I made sure the password was a minimum of 3 characters mainly to prevent the user from simply entering “15”. The formula was calculated and the result was returned. If it matched todays date then the application opened, if the math was bad or the result did not match, the user was presented with an invalid password message. Once I explained to the user how the password worked and demonstrated it, the client asked if I could just set the password to be “access”.