Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added clip_password which copies the generated password to the clipboard #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/passwordy/generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require 'digest'
require 'securerandom'

begin
require 'clipboard'
rescue LoadError
#do nothing, just let clip_password throw an error
end

module Passwordy
class Generator
# Public: Write a salt file to a particular location.
Expand All @@ -16,17 +22,36 @@ def self.write_salt(path)
end
end

# Public: Generate a password for a given resource and copy it to the clipboard(s).
#
# resource - The String name of the thing we want a
# password for.
# master_password - The String master password that is used to
# generate any subsequent passwords.
# len - The length of the password to generate
#
# Examples
#
# clip_password('google.com', 'keyboard cat')
# # => 'd6Pet4qL22iZWBJk5wrzQwX'
#
# Returns a password that can be used for the given resource.
def self.clip_password(resource, master_password, len=23)
Clipboard.copy self.generate_password(resource, master_password, len)
end

# Public: Generate a password for a given resource.
#
# resource - The String name of the thing we want a
# password for.
# master_password - The String master password that is used to
# generate any subsequent passwords.
# len - The length of the password to generate
#
# Examples
#
# generate_password('google.com', 'keyboard cat')
# # => 'e94e5ce8c8ca9affb507ae9e152d4b44'
# # => 'd6Pet4qL22iZWBJk5wrzQwX'
#
# Returns a password that can be used for the given resource.
def self.generate_password(resource, master_password, len=23)
Expand Down