forked from vitorgalvao/tiny-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrongpassword
More file actions
executable file
·46 lines (36 loc) · 1.13 KB
/
Copy pathstrongpassword
File metadata and controls
executable file
·46 lines (36 loc) · 1.13 KB
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
#!/usr/bin/env ruby
require 'cgi'
require 'open-uri'
# password length
if (ARGV[0].nil?) || (ARGV[0] > "64")
pass_len = 64
else
pass_len = ARGV[0].to_i
end
# pbcopy
def pbcopy(input)
str = input.to_s
IO.popen('pbcopy', 'w') { |f| f << str }
str
end
# get passwords as arrays of characters
grc = CGI.unescapeHTML(open('https://www.grc.com/passwords.htm', &:read).split("\n").grep(/ASCII characters:/).to_s.gsub(/.*2>|<.*/, '')).split('')
rorg = open('https://www.random.org/passwords/?num=8&len=24&format=html&rnd=new', &:read).split("\n").grep(/<li>/).last(8).join.to_s.gsub(/<li>|<\/li>/, '').split('')
# number of characters to take from each one
grc_len = rand(pass_len/3..pass_len*2/3)
rorg_len = pass_len - grc_len
tmp_pass = Array.new
final_pass = String.new
# get random characters from each array
grc_len.times do
tmp_pass << grc.delete_at(rand(grc.length))
end
rorg_len.times do
tmp_pass << rorg.delete_at(rand(rorg.length))
end
# get random characters union of both
pass_len.times do
final_pass += tmp_pass.delete_at(rand(tmp_pass.length))
end
pbcopy final_pass
puts "Password copied to clipboard (#{pass_len} characters)"