Class: BashpassPassword

Inherits:
Password
  • Object
show all
Defined in:
app/models/bashpass_password.rb

Constant Summary

Constants inherited from Password

Password::PASSWORD_LENGTH

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Password

#generate!, pwgen_password

Constructor Details

#initializeBashpassPassword

Returns a new instance of BashpassPassword.



3
4
5
# File 'app/models/bashpass_password.rb', line 3

def initialize
  generate!
end

Class Method Details

.bashpass_commandObject



24
25
26
# File 'app/models/bashpass_password.rb', line 24

def self.bashpass_command
  './bashpass -d german.dic -n 4 |tr "&1234567890\`=@+#~\!\%*_^-" " "'
end

.bashpass_dirObject



20
21
22
# File 'app/models/bashpass_password.rb', line 20

def self.bashpass_dir
  YourPlatform::Engine.root.join('vendor/scripts/bashpass').to_s
end

.correct_battery_horse_staple_deObject

This uses bashpass and a German dictionary to generate xkcd passwords like “correct horse battery staple”.

See: vendor/scripts/bashpass



16
17
18
# File 'app/models/bashpass_password.rb', line 16

def self.correct_battery_horse_staple_de
  `cd #{bashpass_dir} && #{osx_shuf_path_workaround} #{bashpass_command}`.gsub("\n", "").gsub(" n ", "")
end

.generateObject



7
8
9
# File 'app/models/bashpass_password.rb', line 7

def self.generate
  correct_battery_horse_staple_de
end

.osx_shuf_path_workaroundObject



28
29
30
# File 'app/models/bashpass_password.rb', line 28

def self.osx_shuf_path_workaround
  'PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"'
end