From 81fa1050a0060b1518e892da899955c4f010ebcf Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Thu, 4 Sep 2008 13:00:58 +0000 Subject: [PATCH] nog hippere versie --- pwdmake/pwdmake | 1 + pwdmake/pwdmake.rb | 101 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100755 pwdmake/pwdmake.rb diff --git a/pwdmake/pwdmake b/pwdmake/pwdmake index bf7e51d..a3715ce 100755 --- a/pwdmake/pwdmake +++ b/pwdmake/pwdmake @@ -3,6 +3,7 @@ # Geen I L O i l o 0 1 @chars=( "A" .. "H", "J", "K", "M", "N", "P" .. "Z", "a" .. "h", "j", "k", "m", "n", "p" .. "z", 2 .. 9, qw(! @ $ % ^ & *) ); + foreach ( 1 .. 8 ) { $passwd = join("", @chars[ map { rand @chars } ( 1 .. 8 ) ]); print "$passwd\n"; diff --git a/pwdmake/pwdmake.rb b/pwdmake/pwdmake.rb new file mode 100755 index 0000000..aea0609 --- /dev/null +++ b/pwdmake/pwdmake.rb @@ -0,0 +1,101 @@ +#!/usr/bin/env ruby + +# $Id$ +# $URL$ + +require "getoptlong" + +def parse_options + @options = {} + begin + opts = GetoptLong.new( + [ "-c", GetoptLong::REQUIRED_ARGUMENT ], + [ "-l", GetoptLong::REQUIRED_ARGUMENT ], + [ "-s", GetoptLong::REQUIRED_ARGUMENT ], + [ "-h", GetoptLong::NO_ARGUMENT ] + ) + opts.quiet=true + opts.each do |opt, arg| + @options[opt] = arg + end + if @options["-h"] + usage + end + rescue GetoptLong::InvalidOption + print "#{$!}\n" + usage + end + # default values + if @options["-s"].nil? + @options["-s"] = "s" + end + if @options["-l"].nil? + @options["-l"] = 8 + end + if @options["-c"].nil? + @options["-c"] = 8 + end + return @options +end + + +def usage + print <] [-l ] [-h] [-s ] + +-c generate this many passwords (default: 8) +-l generate passwords of this length (default: 8) +-s use character set for [S]MS, [P]aper, [T]elephone (default: s) +-h this help message +XXX + exit +end + +def random_string(len) + rand_set_max = @rand_chars.size + rand_max = @rand_chars[0].size + ret = "" + lastpos = -1 + pos = -1 + len.times{ + while pos == lastpos + pos = rand(rand_max) + end + lastpos = pos + char = @rand_chars[rand(rand_set_max)][pos] + if @options["-s"] == "s" && char.chr == '*' + spec_max = @spec_chars.size + char = @spec_chars[rand(spec_max)] + end + ret << char + } + ret +end + +@rand_chars = Array.new +@spec_chars = "" + +parse_options + +case @options["-s"] + # SMS Chars. Available with 1 keypress. + when "s" + @rand_chars = [ "ADGJMPTW*", + "adgjmptw*", + "23456789*" ] + @spec_chars = ",-?!@:;/()" + # Paper chars. No l1I, 0O, g9 + when "p" + @rand_chars = [ "ABCDEFGHJKMNPQRSTUVWXYZabcefhjkmnpqrstuvwxyz2345678!@$%^&*" ] + # Telephone class. No mn, akh and none of the paper chars stuff. + when "t" + @rand_chars = [ "BCDEFGJPQRSTUVWXYZbcefjpqrstuvwxyz2345678!@$%^&*" ] + else + puts "Charater set '#{@options["-s"]}' unknown" + exit +end + +(1 .. @options["-c"].to_i).each { + puts random_string(@options["-l"].to_i) +} +