Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env RBENV_VERSION=1.9.3-preview1 ruby
- require "digest"
- require "sequel"
- module ExpressionEngine
- module Authentication
- ALGORITHMS = {
- 32 => Digest::MD5,
- 40 => Digest::SHA1,
- 64 => Digest::SHA256,
- 128 => Digest::SHA512
- }
- def self.algorithm_for(string)
- ALGORITHMS[string.bytesize]
- end
- end
- def self.authenticate(username, password)
- database = Sequel.connect("mysql://...")
- member = database[:exp_members].first(:username => username)
- return false unless member
- algorithm = Authentication.algorithm_for(member[:password])
- raise "Invalid password hash length (#{member[:password]} bytes)" unless algorithm
- algorithm.hexdigest(member[:salt] + password) == member[:password]
- end
- end
- print "Username: "
- username = gets.chomp
- print "Password: "
- password = gets.chomp
- if ExpressionEngine.authenticate(username, password)
- puts "You're authenticated!"
- else
- puts "Authentication failed."
- end
Add Comment
Please, Sign In to add comment