Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added mk-passwd-hash.

  This spits out a hash which can be used with `usermod -p`
 on Linux, or similar tools on openbsd, solaris, to set a
 password.
  • Loading branch information...
commit be9630bc6e21a51265a6da00861d51201e66594a 1 parent 5b4298d
@skx authored
Showing with 49 additions and 0 deletions.
  1. +49 −0 mk-passwd-hash
View
49 mk-passwd-hash
@@ -0,0 +1,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)
Please sign in to comment.
Something went wrong with that request. Please try again.