Guest User

Untitled

a guest
Jan 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/usr/bin/env RBENV_VERSION=1.9.3-preview1 ruby
  2.  
  3. require "digest"
  4. require "sequel"
  5.  
  6. module ExpressionEngine
  7. module Authentication
  8. ALGORITHMS = {
  9. 32 => Digest::MD5,
  10. 40 => Digest::SHA1,
  11. 64 => Digest::SHA256,
  12. 128 => Digest::SHA512
  13. }
  14.  
  15. def self.algorithm_for(string)
  16. ALGORITHMS[string.bytesize]
  17. end
  18. end
  19.  
  20. def self.authenticate(username, password)
  21. database = Sequel.connect("mysql://...")
  22. member = database[:exp_members].first(:username => username)
  23. return false unless member
  24. algorithm = Authentication.algorithm_for(member[:password])
  25. raise "Invalid password hash length (#{member[:password]} bytes)" unless algorithm
  26. algorithm.hexdigest(member[:salt] + password) == member[:password]
  27. end
  28. end
  29.  
  30. print "Username: "
  31. username = gets.chomp
  32. print "Password: "
  33. password = gets.chomp
  34.  
  35. if ExpressionEngine.authenticate(username, password)
  36. puts "You're authenticated!"
  37. else
  38. puts "Authentication failed."
  39. end
Add Comment
Please, Sign In to add comment