Sponsored Content
Top Forums Shell Programming and Scripting Random Password generator with 2 digits and 6 characters Post 303024060 by Don Cragun on Thursday 27th of September 2018 08:40:37 PM
Old 09-27-2018
This was tested on macOS (instead of AIX), but it should work on AIX as well:
Code:
#!/bin/ksh
LC_ALL=C tr -dc '[:alnum:]' < /dev/urandom | dd cbs=60 conv=unblock | awk '
{	#print "Input line read:", $0
	for(i = 1; i <= length($0); i++)
		a[i] = (substr($0, i, 1) ~ /[[:alpha:]]/)
	for(i = 1; i <= length($0) - 7; i++) {
		if((n = (a[i] + a[i+1] + a[i+2] + a[i+3] + \
		       a[i+4] + a[i+5] + a[i+6] + a[i+7])) == 6) {
		   	printf("Found password \"%s\"\n", substr($0, i, 8))
			exit
		}#else	printf("Tried \"%s\" %d alpha, %d num\n",
		#	    substr($0, i, 8), n, 8 - n)
	}
}'

If you remove the # characters from the above script, it will show you the input it got from /dev/urandom and the possible passwords it tested from that input before reaching a password that meets your criteria.

Note that the dd in the pipeline is because standard implementations of awk are defined to work on text files while the output from the tr command is a single incomplete line of infinite length (while a text file is limited to lines containing no more than LINE_MAX bytes (where LINE_MAX is 2048 bytes on most UNIX systems)). Having dd produce lines of 61 characters per line (counting the terminating <newline> character) was a choice to make the debugging output easy to read in an 80 column window. If you don't care about the debugging output, you might want to increase the line size slightly. Note, however, that even with a line length of just 60 characters, I only saw this script read a second line of input once in 50 tests with debugging output enabled. Furthermore, if you are using an awk that can handle "unlimited" line lengths, the algorithm used in this script will not make any attempt to look for a password until a complete line has been read.
 

9 More Discussions You Might Find Interesting

1. Cybersecurity

Password Generator

I need a great Password Generator program. I looked at a few of them, but none of them seemed to be what I wanted. So I have decided to write my own. (That's the cool thing about being a programmer....I always get what I want in software :) ) Do you have any password generators that you... (13 Replies)
Discussion started by: Perderabo
13 Replies

2. Solaris

Does Solaris have a random number generator?

I am trying to find a way to generate random numbers within a shell script. Does Solaris have a utility that will generate random numbers? Thanks in advance. B (3 Replies)
Discussion started by: one_ring99
3 Replies

3. Shell Programming and Scripting

Random Sentence Generator

Hi, I need to create a table with random sentences. I need lines that are upto 1000 characters in lenght. I need a random sentence generator that will create sentences and output it to a text file. The sentences should be of lenght varying from 1 to 1000. Does anyone know how this can be... (7 Replies)
Discussion started by: kaushys
7 Replies

4. Shell Programming and Scripting

How to replace characters with random characters

I've got a file (numbers.txt) filled with numbers and I want to replace each one of those numbers with a new random number between 0 and 9. This is my script so far: #!/bin/bash rand=$(($RANDOM % 9)) sed -i s//$rand/g numbers.txtThe problem that I have is that it replaces each number with just... (2 Replies)
Discussion started by: hellocatfood
2 Replies

5. Shell Programming and Scripting

Need specialized random string generator script

Hi, I need a script that will generate a set of random strings in sequence, with the ability to predetermine the length, quantity, and alphabet of individual string, and to use the outputs of earlier strings in the sequence to define the parameters of later strings. For examples, I might want... (5 Replies)
Discussion started by: vajrajames
5 Replies

6. Ubuntu

expect script for random password and random commands

Hi I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue: I want expect script for random passwords and random commands generation. please can anyone help me? Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies

7. Cybersecurity

swordfish --- a password generator

Here is my new password generation script. The attachment, swordfish.txt, is in dos format. Remember that you need to use dos2unix or flip or something to get it into unix format. The script is self documenting. It has an extensive help system built-in. And you can run: swordfish "set... (8 Replies)
Discussion started by: Perderabo
8 Replies

8. UNIX for Dummies Questions & Answers

A crude random byte generator...

There was an upload recently on generating a pseudo-random file when /dev/random does NOT exist. This does not need /dev/random, /dev/urandom or $RANDOM either... (I assume $RANDOM relies on the /dev/random device in some way.) This code uses hexdump just because I like hexdump for ease of... (2 Replies)
Discussion started by: wisecracker
2 Replies

9. Shell Programming and Scripting

awk (or) UNIX random RGB colors generator?

Dear UNIX Friends, I was wondering if there is a random RGB color generator or any function in any unix platforms. Please share your ideas. Thanks (2 Replies)
Discussion started by: jacobs.smith
2 Replies
APG(1)								    User Manual 							    APG(1)

NAME
apg - generates several random passwords SYNOPSIS
apg [-a algorithm] [-M mode] [-E char_string] [-n num_of_pass] [-m min_pass_len] [-x max_pass_len] [-r dictfile] [-b filter_file] [-p min_substr_len] [-s] [-c cl_seed] [-d] [-y] [-l] [-t] [-q] [-h] [-v] DESCRIPTION
apg generates several random passwords. It uses several password generation algorithms (currently two) and a built-in pseudo random number generator. Default algorithm is pronounceable password generation algorithm designed by Morrie Gasser and described in A Random Word Generator For Pronounceable Passwords National Technical Information Service (NTIS) AD-A-017676. The original paper is very old and had never been put online, so I have to use NIST implementation described in FIPS-181. Another algorithm is simple random character generation algorithm, but it uses four user-defined symbol sets to produce random password. It means that user can choose type of symbols that should appear in password. Symbol sets are: numeric symbol set (0,...,9) , capital letters symbol set (A,...,Z) , small letters symbol set (a,...,z) and special symbols symbol set (#,@,!,...). Built-in pseudo random number generator is an implementation of algorithm described in Appendix C of ANSI X9.17 or RFC1750 with exception that it uses CAST or SHA-1 instead of Triple DES. It uses local time with precision of microseconds (see gettimeofday(2)) and /dev/random (if available) to produce initial random seed. apg also have the ability to check generated password quality using dictionary. You can use this ability if you specify command-line options -r dictfile or -b filtername where dictfile is the dictionary file name and filtername is the name of Bloom filter file. In that dictionary you may place words (one per line) that should not appear as generated passwords. For example: user names, common words, etc. You even can use one of the dictionaries that come with dictionary password crackers. Bloom filter file should be created with apgbfm(1) utility included in apg distribution. In future releases I plan to implement some other techniques to check passwords (like pattern check) just to make life easier. OPTIONS
Password generation modes options -a algorithm use algorithm for password generation. 0 - (default) pronounceable password generation 1 - random character password generation -n num_of_pass generate num_of_pass number of passwords. Default is 6. -m min_pass_len generate password with minimum length min_pass_len. If min_pass_len > max_pass_len then max_pass_len = min_pass_len. Default mini- mum password length is 8. -x max_pass_len generate password with maximum length max_pass_len. If min_pass_len > max_pass_len then max_pass_len = min_pass_len. Default maxi- mum password length is 10. -M mode Use symbolsets specified with mode for password generation. mode is a text string consisting of characters S, s, N, n, C, c, L, l. Where: S generator must use special symbol set for every generated password. s generator should use special symbol set for password generation. N generator must use numeral symbol set for every generated password. n generator should use numeral symbol set for password generation. C generator must use capital symbol set for every generated password. c generator should use capital symbol set for password generation. L generator must use small letters symbol set for every generated password (always present if pronounceable password generation algorithm is used). l generator should use small letters symbol set for password generation. R,r not supported any more. Use -E char_string option instead. mode can not be more than 4 characters in length. Note: Usage of L, M, N, C will slow down password generation process. Examples: -M sncl or -M SNCL or -M Cn -E char_string exclude characters in char_string from password generation process (in pronounceable password generation mode you can not exclude small letters). To include special symbols that can be recognized by shell (apostrophe, quotes, dollar sign, etc.) in char_string use the backslashed versions. Examples: Command apg -a 1 -M n -n 3 -m 8 -E 23456789 will generate a set of passwords that will look like this 10100110 01111000 11011101 Command apg -a 1 -M nc -n 3 -m 26 -E GHIJKLMNOPQRSTUVWXYZ will generate a set of passwords that will look like this 16A1653CD4DE5E7BD9584A3476 C8F78E06944AFD57FB9CB882BC 8C8DF37CD792D36D056BBD5002 Password quality control options -r dictfile check generated passwords for their appearance in dictfile -b filter_file check generated passwords for their appearance in filter_file. filter_file should be created with apgbfm(1) utility. -p min_substr_len this option tells apg(1) to check every substring of the generated password for appearance in filter_file. If any of such substrings would be found in the filter_file then generated password would be rejected and apg(1) will generate another one. min_substr_len specifies minimum substring length to check. This option is active only if -b option is defined. Pseudo random number generator options -s ask user for random sequence for password generation -c cl_seed use cl_seed as a random seed for password generation. I use it when i have to generate passwords in a shell script. Password output options -d do NOT use any delimiters between generated passwords. I use it when i have to generate passwords in a shell script. -y print generated passwords and crypted passwords (see man crypt(3)) -q quiet mode (do not print warnings) -l spell genetated passwords. Useful when you want to read generated password by telephone. WARNING: Think twice before read your password by phone. -t print pronunciation for generated pronounceable password -h print help information and exit -v print version information and exit DEFAULT OPTIONS
apg -a 0 -M sncl -n 6 -x 10 -m 8 (new style) If you want to generate really secure passwords, you should use option -s. To simplify apg usage, you can write a small shell script. For example: [begin]----> pwgen.sh #!/bin/sh /usr/local/bin/apg -m 8 -x 12 -s [ end ]----> pwgen.sh EXIT CODE
On successful completion of its task, apg will complete with exit code 0. An exit code of -1 indicates an error occurred. Textual errors are written to the standard error stream. DIAGNOSTICS
If /dev/random is not available, apg will display a message about it. FILES
None. BUGS
None. If you've found one, please send bug description to the author. SEE ALSO
apgbfm(1) AUTHOR
Adel I. Mirzazhanov, <a-del@iname.com> Project home page: http://www.adel.nursat.kz/apg/ Automated Password Generator 2003 Aug 04 APG(1)
All times are GMT -4. The time now is 11:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy