forked from skx/sysadmin-util
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmk-passwd-hash
More file actions
executable file
·49 lines (38 loc) · 863 Bytes
/
mk-passwd-hash
File metadata and controls
executable file
·49 lines (38 loc) · 863 Bytes
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
#!/usr/bin/ruby
#
# This script will prompt for a password and then output
# a hash which may be used with 'usermod'.
#
# Using usermod you can script the changine of passwords
# for users.
#
# NOTE: Intentionally doesn't allow passwords to be entered
# via the command-line.
#
#
# The random pool from which salts will be taken.
#
SALT = ([*('/' '.'),*('A'..'Z'),*('a'..'z'), *('0'..'9')]).sample(8).join
#
# Prompt for the password, twice to be sure.
#
puts "Please enter your plaintext password:"
pass1 = gets().chomp
puts "Please confirm your password:"
pass2 = gets().chomp
#
# Ensure they match
#
if ( pass1 != pass2 )
puts "Your passwords did not match. Aborting"
exit 1
end
#
# Do the magic.
#
hash = pass1.crypt("$1$"+8.times.collect{SALT[rand(SALT.length)]}.join+"$")
#
# We're done.
#
puts "Your hash is \t#{hash}\n"
exit(0)