LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2010, 04:54 AM   #1
joshua.smith7
LQ Newbie
 
Registered: Mar 2010
Location: holsworthy
Distribution: Ubuntu 9.4
Posts: 2

Rep: Reputation: 0
Exclamation 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.

Last edited by joshua.smith7; 03-16-2010 at 05:05 AM.
 
Old 03-16-2010, 05:49 AM   #2
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
Unless you really need it to be in the exact form of XX<garbage><num><num> I would check out pwgen
 
Old 03-16-2010, 06:03 AM   #3
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
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
 
Old 10-22-2010, 07:18 PM   #4
multivers88888
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Rep: Reputation: 0
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/
 
Old 10-23-2010, 10:33 AM   #5
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 10-23-2010, 12:00 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
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
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 05:39 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 08:40 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 10:48 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration