LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A little script help (https://www.linuxquestions.org/questions/programming-9/a-little-script-help-795729/)

joshua.smith7 03-16-2010 04:54 AM

A little script help
 
Hey everybody.

I not sure if this can be done.


I am using this script at the moment. It a little password generator
script I was wondering if anyone could help me out.

I would like the First letter to be a Capital and the last two to be any
digits (number's)?

The one that I have puts capitals all over the place and sometimes it
does not have any number's at all.

I plan to use this for work for the I have run out of things to
put as my password and I am not aloud to have the same password twice

Quote:

#!/bin/bash

LORD="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789"
LENGTH="14"
while [ "${n:=1}" -le "$LENGTH" ]
do
PASS="$PASS${LORD:$(($RANDOM%${#LORD})):1}"
let n+=1
done
echo "$PASS"
exit
Thanks in advance Josh.

Dinithion 03-16-2010 05:49 AM

Unless you really need it to be in the exact form of XX<garbage><num><num> I would check out pwgen

blacky_5251 03-16-2010 06:03 AM

Let me know if you want anything explained ;)
Code:

#!/bin/bash
Random() {
  ((i = $RANDOM * $1 / 32767 + $2))
  echo $i
}

LORD="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789"
PASS="${LORD:$(Random 26 0):1}"
LENGTH="11"
while [ "${n:=1}" -le "$LENGTH" ]
do
PASS="$PASS${LORD:$(Random ${#LORD} 0):1}"
let n+=1
done
PASS="$PASS${LORD:$(Random 9 52):1}"
PASS="$PASS${LORD:$(Random 9 52):1}"
echo "$PASS"
exit


multivers88888 10-22-2010 07:18 PM

I would use apg for this...
 
Hy,
apg = Automated password generator

it has many options:
* -n -> number of generated possword
* -m -> min number of caracters that password contains
* -x -> max number of caracters that password contains
* -M -> mode: N must use numbers, C must use capitals, L must use small letters

You can take a look here as well:

http://7dpo.com/

XavierP 10-23-2010 10:33 AM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

grail 10-23-2010 12:00 PM

How about a little awk :)
Code:


#!/usr/bin/awk -f

BEGIN{
    srand()

    do{
        printf("Please enter the length for your password: ")
        getline len < "-"
    }while(len !~ /^[[:digit:]]+$/)

    c = len

    while(c-- > 0){
        if( c + 1 == len ){
            rnd_len = 26
            rnd_start = 65
        }
        else{

            if( c <= 1 ){
                rnd_len = 10
                rnd_start = 48
            }
            else{
                rnd_len = 94
                rnd_start = 33
            }
      }

        rnd = int(rand() * rnd_len) + rnd_start
        pwd = pwd sprintf("%c",rnd)
    }

    print pwd
}



All times are GMT -5. The time now is 10:45 AM.