Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #26480
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: random password generator |
| Date | 2013-10-13 12:27 -0700 |
| Organization | Nightsong/Fort GNOX |
| Message-ID | <7xbo2tc6pn.fsf@ruckus.brouhaha.com> (permalink) |
| References | <7x38o5zzwz.fsf@ruckus.brouhaha.com> <l3ep0h$43g$1@online.de> |
Bernd Paysan <bernd.paysan@gmx.de> writes: > This is a script. Things you just need to do once (e.g. open /dev/random) > don't need to go into a definition. Just do them in interactive mode. Thanks! Hmm, ok, I thought it was easier to debug and test stuff by putting all the code into definitions, though in a very simple script like this it probably doesn't matter much. > Use throw on iors. Thanks, that's useful. I just found the info in the exceptions chapter of the gforth manual. That took a little searching because throw isn't in the word index (maybe you could add it): http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Word-Index.html > If you have questions whether your alphabet really is 64 characters, > add a ~~ right after the string once for debugging. Yeah the assert was kind of a built-in unit test. I generally prefer to leave things like that in programs if I don't mind the tiny bit of bloat. It's mostly to catch if I make a mistake in a later modification, rather than to check that the code works in the first place. > Here's how I would do it: > > #! /usr/bin/gforth > > s" /dev/urandom" r/o open-file throw value rndfd > : randombyte ( -- c ) rndfd key-file ; > : >alphabet ( n -- c ) $3F and > s" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=" > drop + c@ ; > : passwd ( len -- ) 0 ?DO randombyte >alphabet emit LOOP cr ; > > 12 passwd bye That is nice! I didn't know about key-file either. > : >alphabet ( u16 -- c ) > s" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=" > rot * 16 rshift + c@ ; Don't you mean : >alphabet ( u16 -- c ) s" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=" rot swap mod + c@ ; I considered something like that but I figured that the 6-bit alphabet (or even a 5-bit one) was more in the spirit of Forth minimalism. I haven't seen any recent systems that don't allow mixed case passwords but some obnoxious ones -require- the presence of both cases and digits (that's why I used 6 bits instead of 5). I decided that most passwords from this script have that because of their length, and I could just run the script several times if necessary. > BTW: Test what you have written, word by word. Your chk does not work, > because "dup =" is always true. Yes, result of a last-minute refactoring :(. I posted a correction.
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
random password generator Paul Rubin <no.email@nospam.invalid> - 2013-10-12 19:07 -0700
Re: random password generator hughaguilar96@yahoo.com - 2013-10-12 22:01 -0700
Re: random password generator Paul Rubin <no.email@nospam.invalid> - 2013-10-12 22:32 -0700
Re: random password generator hughaguilar96@yahoo.com - 2013-10-12 22:44 -0700
Re: random password generator "WJ" <w_a_x_man@yahoo.com> - 2013-10-13 08:23 +0000
Re: random password generator Paul Rubin <no.email@nospam.invalid> - 2013-10-13 05:46 -0700
Re: random password generator "WJ" <w_a_x_man@yahoo.com> - 2013-10-13 17:09 +0000
Re: random password generator Bernd Paysan <bernd.paysan@gmx.de> - 2013-10-13 20:32 +0200
Re: random password generator Paul Rubin <no.email@nospam.invalid> - 2013-10-13 12:27 -0700
Re: random password generator Bernd Paysan <bernd.paysan@gmx.de> - 2013-10-13 22:52 +0200
Re: random password generator Paul Rubin <no.email@nospam.invalid> - 2013-10-13 14:43 -0700
csiph-web