Please help me modify this

This currently works:

define defaults which can be

overridden from the command prompt

$minlen = 7
$maxlen = 9

generator function

def generate_password(minlen=$minlen, maxlen=$maxlen)
chars = (“a”…“z”).to_a + (“A”…“Z”).to_a + (0…9).to_a
pwlen = rand(maxlen - minlen) + minlen + 1
(1…pwlen).to_a.collect {|x| chars[rand(chars.length)] }.join
end

puts generate_password

I am trying to add a $strength variable as well. 1 would be
(“a”…“z”).to_a 2 would be (“a”…“z”).to_a + (“A”…“Z”).to_a and 3
would be the current one. I tryed splitting it out with an IF…ELSIF
like:

if $strength == 1 then
chars = (“a”…“z”).to_a
elsif $strength == 2 then
chars = (“a”…“z”).to_a + (“A”…“Z”).to_a
elsif $strength == 3 then
chars = (“a”…“z”).to_a + (“A”…“Z”).to_a + (0…9).to_a

Doesn’t seem to like that…I am also gonna do a GetoptLong to take
command
line parameters to override the defaults but I need to get past the
split out.

Also how would I add symbols (i.e. ~ ! @ # $ % ^ & * ( ) + = )?

Help is much appreciated…

Bob

For a similar problem in my CA code (See RAA) I used an alphabet

class Password
ALPHABET=‘qwertyQWERTY123456’

SHORT=6
MEDIUM=12
LONG=18

def Password.create(length=8, strength=MEDIUM)
password = ‘’

 (0...length).times { password << ALPHABET[rand(strength)] }

 return password

end
end

Warning, untested code!

You get the idea.

Bob wrote:

This currently works:

define defaults which can be

overridden from the command prompt

$minlen = 7
$maxlen = 9

generator function

def generate_password(minlen=$minlen, maxlen=$maxlen)
chars = (“a”…“z”).to_a + (“A”…“Z”).to_a + (0…9).to_a
chars = [(“a”…“z”).to_a, (“A”…“Z”).to_a, (0…9).to_a
][0…($strength-1)].join

pwlen = rand(maxlen - minlen) + minlen + 1
(1..pwlen).to_a.collect {|x| chars[rand(chars.length)] }.join
  (1..pwlen).collect{|x| chars[rand(chars.length)].chr }
  # Since chars has changed from an array to string, in my above

version.

end

puts generate_password

I am trying to add a $strength variable as well. 1 would be
(“a”…“z”).to_a 2 would be (“a”…“z”).to_a + (“A”…“Z”).to_a and 3
would be the current one. I tryed splitting it out with an IF…ELSIF
like:

HTH

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

class Password
ALPHABET=‘qwertyQWERTY123456’

SHORT=6
MEDIUM=12
LONG=18

def Password.create(length=8, strength=MEDIUM)
password = ‘’
(0…length).times { password << ALPHABET[rand(strength)] }
1.upto( length ) { password << ALPHABET[rand(strength)] }

···

In message “Please help me modify this…” on 30.10.2002, Peter Hickman peter@semantico.com writes:

 return password

end
end


Mit freundlichen Gruessen,
Wild Karl-Heinz
kh.wild at wicom.li