-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-pass
executable file
·75 lines (58 loc) · 1.23 KB
/
new-pass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/ruby -w
USAGE = <<__
new-pass [-a] [-s] [#...]
Choose a new password from the alphanumeric set (-a) or the symbolic
set (-s, the default). # is the password length, it can be specified
multiple times for multiple passwords.
The arguments can be intermixed. No arguments is equivalent to -a 8.
One byte from /dev/random is used to select one character from the
set.
Examples:
% new-pass
I96Cm2OJ
% new-pass 64 8 -a 8
ttzg!RQya(gN&W2$J,+5i{_f3]Qd^X+9^utI*wfO9xcappr]tGIK]ys:!wQ=,>=Q
GefH>?1<
J2xnNEtU
__
def p(*a) end
unless ARGV.size > 0
ARGV.unshift "8"
ARGV.unshift "-a"
end
ALPHANUMERIC = [
('a'..'z').to_a,
('A'..'Z').to_a,
('0'..'9').to_a,
].flatten
SYMBOLS = "~!@#\$%^&*()_+-={}[]|\:\";'<>,.?/"
SYMBOLIC = [
ALPHANUMERIC,
SYMBOLS.split(//)
].flatten
raise unless SYMBOLIC.size == (ALPHANUMERIC.size + SYMBOLS.size)
set = SYMBOLIC
open "/dev/random" do |io|
ARGV.each do |arg|
case arg
when "-h"
puts USAGE
exit 1
when "-a"
set = ALPHANUMERIC
when "-s"
set = SYMBOLIC
else
pass = ""
arg.to_i.times do
b = io.read(1)
i = b.unpack("c").first
p [b, i]
c = set[i % set.size]
pass << c
p [b, i, c, pass]
end
puts pass
end
end
end