Commit 4806d489 authored by Mathieu Valois's avatar Mathieu Valois
Browse files

Fix regression for min digits & co.

parent aa4b3e01
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -8,13 +8,13 @@

class Policy {
public:
	int digit = 0;
	int lower = 0;
	int upper = 0;
	int special = 0;
	uint digit = 0;
	uint lower = 0;
	uint upper = 0;
	uint special = 0;
	operator std::string() const;
	static std::map<int, std::string> charsetNames() {
		std::map<int, std::string> names;
	static std::map<uint, std::string> charsetNames() {
		std::map<uint, std::string> names;
		names[1] = "numeric";
		names[2] = "loweralpha";
		names[3] = "loweralphanum";
@@ -32,7 +32,7 @@ public:
		names[15]= "all";
		return names;
	}
	bool satisfies(const SecurityRules& sr, const int& pwd_size) const;
	bool satisfies(const SecurityRules& sr, const uint& pwd_size) const;
};

#endif
 No newline at end of file
+5 −5
Original line number Diff line number Diff line
@@ -4,11 +4,11 @@

struct SecurityRules {
	uint64_t nbSecurePassword;
	int minLength;
	int minSpecial;
	int minDigit;
	int minLower;
	int minUpper;
	uint minLength;
	uint minSpecial;
	uint minDigit;
	uint minLower;
	uint minUpper;
};


+11 −9
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <regex>
#include <queue>
#include <thread>
#include <climits>

#include "Policy.h"
#include "SecurityRules.h"
@@ -41,16 +42,17 @@ struct PasswordStats {

/**
 * @brief Simplify number of arguments for functions
 * minimal number of digits of a password, etc.
 */
struct minMax {
	int mindigit = -1;				// save the number minimum of digit in a password
	int maxdigit = -1;				// save the number maximum of digit in a password
	int minlower = -1;				// save the number minimum of lower in a password
	int maxlower = -1;				// save the number maximum of lower in a password
	int minupper = -1;				// save the number minimum of upper in a password
	int maxupper = -1;				// save the number maximum of upper in a password
	int minspecial = -1;			// save the number minimum of special character in a password
	int maxspecial = -1;			// save the number maximum of special character in a password
	uint mindigit = UINT_MAX;
	uint maxdigit = 0;
	uint minlower = UINT_MAX;
	uint maxlower = 0;
	uint minupper = UINT_MAX;
	uint maxupper = 0;
	uint minspecial = UINT_MAX;
	uint maxspecial = 0;
};

/**
@@ -164,7 +166,7 @@ public:
	 * @brief Defining all security rules
	 */
	void askSecurityRules();
	void setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower);
	void setSecurityRules(const uint& length, const uint& special, const uint& digit, const uint& upper, const uint& lower);

	/**
	 * @brief Where to write masks
+4 −4
Original line number Diff line number Diff line
@@ -2,21 +2,21 @@

using namespace std;

static const map<int, string> charset_names = Policy::charsetNames();
static const map<uint, string> charset_names = Policy::charsetNames();


Policy::operator string() const {
	int charset = 0;
	uint charset = 0;
	charset ^= (bool) digit << 0;
	charset ^= (bool) lower << 1;
	charset ^= (bool) upper << 2;
	charset ^= (bool) special << 3;

	map<int, string>::const_iterator it = charset_names.find(charset);
	map<uint, string>::const_iterator it = charset_names.find(charset);
	return it->second;
}

bool Policy::satisfies(const SecurityRules& sr, const int& pwd_size) const {
bool Policy::satisfies(const SecurityRules& sr, const uint& pwd_size) const {
	return 	pwd_size >= sr.minLength
			&& digit >= sr.minDigit
			&& lower >= sr.minLower
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ Statsgen::Statsgen(const std::string& name):filename(name){


void Statsgen::askSecurityRules() {
	int length, special, digit, upper, lower;
	uint length, special, digit, upper, lower;
	cout << "Minimal length of a password:" << endl;
	cin >> length;

@@ -48,7 +48,7 @@ void Statsgen::askSecurityRules() {
	setSecurityRules(length, special, digit, upper, lower);
}

void Statsgen::setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower) {
void Statsgen::setSecurityRules(const uint& length, const uint& special, const uint& digit, const uint& upper, const uint& lower) {
	_sr = { _sr.nbSecurePassword, length, special, digit, upper, lower };
}