Guest User

Untitled

a guest
May 31st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. require 'activesupport'
  2. module Password
  3. VERSION = '1.0.0'
  4. FILENAME = "#{ENV['HOME']}/.they_stole_my_facebook_login_oh_noez" # honestly, "security", who gives a shit
  5. SITES = {}
  6. def set(credentials)
  7. SITES[credentials[:site]] = {:username => credentials[:username],
  8. :password => credentials[:password]}
  9. end
  10. def username(site)
  11. SITES[site][:username]
  12. end
  13. def password(site)
  14. SITES[site][:password]
  15. end
  16. def save_passwords
  17. File.open(FILENAME, "w") {|file| file.puts SITES.to_yaml}
  18. end
  19. def load_passwords
  20. if File.exists?(FILENAME)
  21. SITES.merge!(YAML::load(File.open(FILENAME)))
  22. else
  23. {}
  24. end
  25. end
  26. def generate(length = 23)
  27. # how to make this elegant?
  28. password = ""
  29. possible = %w{0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l M N O P Q R S T U V W X Y Z ! $ # @ & * . ' =}
  30. length.times {password << possible[rand(possible.size)]}
  31. password
  32. end
  33. end
Add Comment
Please, Sign In to add comment