Random passwords generation (Python vs Perl) =)

G

Gabriel Genellina

Perl:
@char=("A".."Z","a".."z",0..9);
do{print join("",@char[map{rand @char}(1..8)])}while(<>);

!!generate passwords untill U press ctrl-z



Python (from CookBook):

from random import choice
import string
print ''.join([choice(string.letters+string.digits) for i in
range(1,8)])

!!generate password once :(

who can write this smaller or without 'import'?

Isn't it small enough? What's the point on being shorter?
I think you could avoid importing string (building the set of characters
like the Perl code) but anyway you will end importing random, or os.urandom
Do you want more than one password? Wrap the print inside a while True:
statement.
 
H

Hieu.D.Hoang

WOW! :shock:

in this case:

while 1:i=__import__;print
i('binascii').b2a_base64(i('os').urandom(6)),;raw_input()

raw_input can do the job of print
while 1: raw_input(__import__('os').urandom(6).encode('base64'))

And can anyone explain why this is so?....
BgiWdv//

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 0

^
SyntaxError: unexpected EOF while parsing

Thank to all, I learned a lot of new things from this thread.

Hieu
 
G

Gabriel Genellina

En Wed, 31 Jan 2007 01:08:28 -0300, (e-mail address removed)
raw_input can do the job of print
while 1: raw_input(__import__('os').urandom(6).encode('base64'))

And can anyone explain why this is so?
^
SyntaxError: unexpected EOF while parsing

input and raw_input are not the same, see the docs.
 
M

Marc 'BlackJack' Rintsch

In <[email protected]>,
And can anyone explain why this is so?
...
BgiWdv//

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 0

^
SyntaxError: unexpected EOF while parsing

It's `input()` that expects a valid Python expression. An empty one
doesn't work, it has to evaluate to something.

In [2]: input()

------------------------------------------------------------
File "<string>", line 0

^
SyntaxError: unexpected EOF while parsing

Ciao,
Marc 'BlackJack' Rintsch
 
M

Magnus Lycka

NoName said:
Perl:
@char=("A".."Z","a".."z",0..9);
do{print join("",@char[map{rand @char}(1..8)])}while(<>);

If you generate passwords like that to normal computer
users, you'll end up with a lot of "my password doesn't
work" tickets. You should skip the symbols that are
easy to mistake for each other.

Skip at least Il1 and 0O. On the other hand, you could
probably use other characters besides letters and digits
to make the passwords stronger. Which ones to use is
unfortunately platform dependent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top