Skip to content

Commit

Permalink
Password Strength Checker #22
Browse files Browse the repository at this point in the history
  • Loading branch information
AmadeuszLakoma committed Apr 15, 2024
1 parent aec2842 commit 020857b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
39 changes: 39 additions & 0 deletions source/Backend/PasswordChecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "PasswordChecker.hpp"
#include <regex>

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 PasswordChecker::hasMinimumLength() const {
return password.length() >= 8;
}

bool PasswordChecker::hasMinimumUppercase() const {
return std::regex_search(password, std::regex("[A-Z]"));
}

bool PasswordChecker::hasMinimumLowercase() const {
return std::regex_search(password, std::regex("[a-z]"));
}

bool PasswordChecker::hasMinimumDigit() const {
return std::regex_search(password, std::regex("[0-9]"));
}

bool PasswordChecker::hasMinimumSpecialChar() const {
return std::regex_search(password, std::regex("[^a-zA-Z0-9]"));
}
23 changes: 23 additions & 0 deletions source/Backend/PasswordChecker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <string>

class PasswordChecker {
public:
PasswordChecker(const std::string& password);

bool isSafe();

private:
std::string password;

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;
};

0 comments on commit 020857b

Please sign in to comment.