diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /appl/cmd/randpass.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/cmd/randpass.b')
| -rw-r--r-- | appl/cmd/randpass.b | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/appl/cmd/randpass.b b/appl/cmd/randpass.b new file mode 100644 index 00000000..074b21ac --- /dev/null +++ b/appl/cmd/randpass.b @@ -0,0 +1,45 @@ +implement Randpass; + +include "sys.m"; + sys: Sys; + stderr: ref Sys->FD; + +include "draw.m"; + +include "keyring.m"; + kr : Keyring; + IPint: import kr; + +Randpass: module +{ + init: fn(nil: ref Draw->Context, nil: list of string); +}; + +init(nil: ref Draw->Context, args: list of string) +{ + sys = load Sys Sys->PATH; + kr = load Keyring Keyring->PATH; + + if(args != nil) + args = tl args; + pwlen := 16; + if(args != nil){ + if(!isnumeric(hd args) || (pwlen = int hd args) <= 8 || pwlen > 256){ + sys->fprint(sys->fildes(2), "Usage: randpass [password-length(<256, default=16)]\n"); + raise "fail:usage"; + } + } + + rbig := IPint.random(pwlen*8, pwlen*16); + rstr := rbig.iptob64(); + + sys->print("%s\n", rstr[0:pwlen]); +} + +isnumeric(s: string): int +{ + for(i := 0; i < len s; i++) + if(!(s[i]>='0' && s[i]<='9')) + return 0; + return i > 0; +} |
