Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. require 'yaml'
  3. require 'dbi'
  4. require 'digest/sha1'
  5.  
  6. dbconfig = YAML::load(File.open("/usr/share/redmine/config/database.yml"))["production"]
  7.  
  8. dbname = dbconfig["database"]
  9. username = dbconfig["username"]
  10. dbpassword = dbconfig["password"]
  11. host = dbconfig["host"]
  12.  
  13. connstr = "DBI:Mysql:" + dbname
  14. connstr += ":" + host if host != nil
  15.  
  16. login = gets.strip
  17. password = gets.strip
  18.  
  19. hashed_password,salt = DBI.connect(connstr, username, dbpassword) {|dbh|
  20. dbh.select_one("select hashed_password,salt from users where type='User' and login=?", login)
  21. }
  22.  
  23. exit(2) if hashed_password == nil || salt == nil
  24. exit(1) if Digest::SHA1.hexdigest(salt+Digest::SHA1.hexdigest(password)) != hashed_password
Add Comment
Please, Sign In to add comment