Sha256: 5d6a846b7d987bdcc3ef8bb4ce2a8076ee0e7e00cae543f3ed58217943d4dc31
Contents?: true
Size: 986 Bytes
Versions: 2
Compression:
Stored size: 986 Bytes
Contents
#!/usr/bin/env ruby require 'yaml' require 'digest/sha2' admins = [] begin f = File.open("config/admin.yml","r") admins = YAML::load f.read f.close rescue end id = "" while true do print 'New Admin ID : ' line = readline id = line.gsub /\n/,'' break unless admins.find {|u| u[:id] == id} puts "#{id} already exists." end while true do print 'Password : ' system "stty -echo" line = readline pwd1 = line.gsub /\n/,'' system "stty echo" print "\nPassword Confirm : " system "stty -echo" line = readline pwd2 = line.gsub /\n/,'' system "stty echo" if pwd1 == pwd2 break end puts "\nPasswords don't match." end #make admin salt = [Array.new(8){rand(256).chr}.join].pack('m').chomp hash = Digest::SHA512.hexdigest(pwd1 + salt) new_admin = {:id => id, :password_salt => salt, :password_hash => hash} admins << new_admin f = File.open("config/admin.yml", "w") f.write YAML::dump admins f.close puts "\nNew admin #{id} created."
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
drh_admin-0.0.4 | lib/generators/admin/templates/script/new_admin |
drh_admin-0.0.3 | lib/generators/admin/templates/script/new_admin |