-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
020857b
commit 5d05783
Showing
2 changed files
with
30 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
#include "PasswordChecker.hpp" | ||
#include <regex> | ||
|
||
PasswordChecker::PasswordChecker(const std::string& password) : password(password) {} | ||
PasswordChecker::PasswordChecker(const std::string& password) | ||
: password(password) {} | ||
|
||
bool PasswordChecker::isSafe() { | ||
bool hasMinimumLength_ = hasMinimumLength(); | ||
bool hasMinimumUppercase_ = hasMinimumUppercase(); | ||
bool hasMinimumLowercase_ = hasMinimumLowercase(); | ||
bool hasMinimumDigit_ = hasMinimumDigit(); | ||
bool hasMinimumSpecialChar_ = hasMinimumSpecialChar(); | ||
|
||
return | ||
hasMinimumLength_ && | ||
hasMinimumUppercase_ && | ||
hasMinimumLowercase_ && | ||
hasMinimumDigit_ && | ||
hasMinimumSpecialChar_; | ||
bool hasMinimumLength_ = hasMinimumLength(); | ||
bool hasMinimumUppercase_ = hasMinimumUppercase(); | ||
bool hasMinimumLowercase_ = hasMinimumLowercase(); | ||
bool hasMinimumDigit_ = hasMinimumDigit(); | ||
bool hasMinimumSpecialChar_ = hasMinimumSpecialChar(); | ||
|
||
return hasMinimumLength_ && hasMinimumUppercase_ && hasMinimumLowercase_ && | ||
hasMinimumDigit_ && hasMinimumSpecialChar_; | ||
} | ||
|
||
bool PasswordChecker::hasMinimumLength() const { | ||
return password.length() >= 8; | ||
return password.length() >= 8; | ||
} | ||
|
||
bool PasswordChecker::hasMinimumUppercase() const { | ||
return std::regex_search(password, std::regex("[A-Z]")); | ||
return std::regex_search(password, std::regex("[A-Z]")); | ||
} | ||
|
||
bool PasswordChecker::hasMinimumLowercase() const { | ||
return std::regex_search(password, std::regex("[a-z]")); | ||
return std::regex_search(password, std::regex("[a-z]")); | ||
} | ||
|
||
bool PasswordChecker::hasMinimumDigit() const { | ||
return std::regex_search(password, std::regex("[0-9]")); | ||
return std::regex_search(password, std::regex("[0-9]")); | ||
} | ||
|
||
bool PasswordChecker::hasMinimumSpecialChar() const { | ||
return std::regex_search(password, std::regex("[^a-zA-Z0-9]")); | ||
return std::regex_search(password, std::regex("[^a-zA-Z0-9]")); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
#include <string> | ||
|
||
class PasswordChecker { | ||
public: | ||
PasswordChecker(const std::string& password); | ||
public: | ||
PasswordChecker(const std::string& password); | ||
|
||
bool isSafe(); | ||
bool isSafe(); | ||
|
||
private: | ||
std::string password; | ||
private: | ||
std::string password; | ||
|
||
bool hasMinimumLength_; | ||
bool hasMinimumUppercase_; | ||
bool hasMinimumLowercase_; | ||
bool hasMinimumDigit_; | ||
bool hasMinimumSpecialChar_; | ||
bool hasMinimumLength_; | ||
bool hasMinimumUppercase_; | ||
bool hasMinimumLowercase_; | ||
bool hasMinimumDigit_; | ||
bool hasMinimumSpecialChar_; | ||
|
||
bool hasMinimumLength() const; | ||
bool hasMinimumUppercase() const; | ||
bool hasMinimumLowercase() const; | ||
bool hasMinimumDigit() const; | ||
bool hasMinimumSpecialChar() const; | ||
bool hasMinimumLength() const; | ||
bool hasMinimumUppercase() const; | ||
bool hasMinimumLowercase() const; | ||
bool hasMinimumSpecialChar() const; | ||
bool hasMinimumDigit() const; | ||
}; |