Share your repls and programming experiences

← Back to all posts
Simple Password Generator
oraybyte (0)

Secure Password Generator

Description

This short script generates a random password that includes numbers, symbols, and letters (upper and lower case).

Why

I was bored and have always had a hard time thinking of secure passwords. I was tired of going to websites to get randomly generated password so I made my own to run on my PC.

How it works

I use the function generatePassword() to return a string that is the password.

The way the generatePassword() function works is by changing the random seeded series by setting it with time(NULL), obtaining a random int from randomNumber(), converting the int into a char, and then concatenating the password with the new random characters.

However, a password is not too secure if the generator generates the same passwords every time it is compiled.

To combat this, I made the randomNumber() function.

The randomNumber() functions returns a random number between the specified min and max values. The rand() function returns a random number between 0 and RAND_MAX. To establish a range, you must do rand() % (max - min) + min.

Things to note

srand(time(NULL)) is called in generatePassword() rather than randomNumber() because if srand(time(NULL)) is called in too short of time, the random series will be the same, causing the password to be all the same character. If srand(time(NULL)) is called in generatePassword(), it is less likely that the user will run into the problem of not being enough time for srand(time(NULL)) to change the random series. If that does happen, however, the user can simply say they are not satisfied with their password and get a completely new password!