[Tutor] Convert os.random output to a string

Alan Gauld alan.gauld at btinternet.com
Fri Mar 7 01:34:39 CET 2014


On 06/03/14 23:32, Jay Lozier wrote:

> I am try to generate random password strings of an arbitrary user
> selected length. I read to generate a random string of a user supplied
> length I can use os.urandom(n).

So far so good...

 > I want to convert the output to a human readable string.

Define human readable?

> I would like to store the string for later processing.

Depending on the application there may be laws/rules/guidance 
prohibiting the storage of passwords. Best practice only ever
stores the encrypted form not the original password (or more
properly nowadays pass-phrase since phrases are more secure
than words.)

> Also, I would like to limit the characters to the US keyboard, so I
> might be using the wrong function.

Even in the US not everyone uses a "US keyboard" especially nowadays 
with various tablets/phablets/phones in use. but if you stick to the 
printable subset of the old ASCII set you should be close enough...
But that probably means building your own random generator based
on the subrange of characters.

> I am probably missing something very obvious.

Maybe, or you could be asking for more than the library gives?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list