Created
April 16, 2017 02:50
-
-
Save picatz/729979924e97cb6b3b7fcff60bab777b to your computer and use it in GitHub Desktop.
Violent Ruby: Unix Password Cracker Check Password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if a given encrypted password matches a given plaintext | |
# word when the same crytographic operation is performed on it. | |
# | |
# @example Basic Usage | |
# ViolentRuby::UnixPasswordCracker.new.check_password('HX9LLTdc/jiDE', 'egg') | |
# # true | |
# | |
# @example Advanced Usage | |
# ViolentRuby::UnixPasswordCracker.new.check_password('HXA82SzTqypHA', 'egg ') | |
# # false | |
# | |
# ViolentRuby::UnixPasswordCracker.new.check_password('HXA82SzTqypHA', 'egg ', false) | |
# # true | |
# | |
# @param encrypted_password [String] The encrypted password to check against. | |
# @param word [String] The plaintext password to check against. | |
# @param strip [Boolean] Strip trailing spaces and newlines from word ( default: +true+ ) | |
# | |
# @return [Boolean] | |
def check_password(encrypted_password, word, strip = true) | |
word.strip! if strip # sometimes passwords have trailing spaces!? D: | |
if word.strip.crypt(encrypted_password[0, 2]) == encrypted_password | |
true | |
else | |
false | |
end | |
end | |
# Same same, but different, but still same. | |
alias cracked? check_password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment