How to Create a Bash Script for a Password Generator?

0
6
Asked By CuriousCoder42 On

I'm looking to set up a bash script that generates passwords. My idea is to use two lists of words and randomly select one word from each list. I'd like to add a random special character at the end, followed by a random assortment of four numbers. Any suggestions on how to implement this?

3 Answers

Answered By ScriptNinja88 On

You can definitely do that! In bash, you can define a list of special characters and use the `RANDOM` variable to pick random items. For example, you could combine two randomly selected words from a dictionary, a random special character, and a four-digit number like this:

```bash
rand_chars='!@#$%^&*()_+-=[]{}|;:,.';
num_chars=${#rand_chars};
ridx=$((RANDOM % num_chars));
printf "$(shuf -n 1 /usr/share/dict/words)$(shuf -n 1 /usr/share/dict/words)${rand_chars:$ridx:1}$(printf "%04d" $((RANDOM % 10000)))n"
```
This way, you'll have a nice mix! If you're looking for simplicity, consider using Python or Perl too, as they have libraries that make this even easier.

Answered By DevGuru77 On

Just a heads up, while bash can work for this, if you’re comfortable with PowerShell, there are a lot of existing scripts out there that can do the same thing. Plus, if you really want to ensure your password security, focus on length — combining 4 or 5 words from a dictionary is often more effective than just a couple of words and a few numbers.

Answered By CodeWhisperer99 On

Also, check out this password generator resource: fortypoundhead.com/showcontent.asp?artid=24579. It has a specific section for generators that might give you some solid ideas!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.