Commit e2918010 authored by Mathieu Valois's avatar Mathieu Valois
Browse files

Policy & SecurityRules in own files

parent 701fa268
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ set(CMAKE_LD_FLAGS "-lpthread")

add_executable(cppack
				src/core/statsgen.cpp
				src/core/Policy.cpp
				src/cli/main.cpp)
target_link_libraries(cppack ${CMAKE_THREAD_LIBS_INIT})

@@ -40,6 +41,7 @@ if(Qt5Core_FOUND)
	    src/gui/mainwindow.cpp
	    src/gui/maingui.cpp
	    src/core/statsgen.cpp
	    src/core/Policy.cpp
	)

	target_link_libraries(cppack-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Charts ${CMAKE_THREAD_LIBS_INIT})
+3 −45
Original line number Diff line number Diff line
@@ -22,22 +22,14 @@
#include <queue>
#include <thread>

#include "Policy.h"
#include "SecurityRules.h"

#define MAX_THREADS 32

typedef std::unordered_map<std::string, uint64_t> StringOccurrence;
typedef std::unordered_map<int, uint64_t> IntOccurrence;

/**
 * @brief Simplify number of arguments for functions
 */
struct Policy {
	int digit = 0;
	int lower = 0;
	int upper = 0;
	int special = 0;
};


/**
 * @brief Simplify number of arguments for functions
 */
@@ -64,20 +56,6 @@ struct minMax {
	int maxspecial = -1;			// save the number maximum of special character in a password
};


/**
 * @brief All needed variables for the security rules
 */
struct SecurityRules {
	uint64_t nbSecurePassword;
	int minLength;
	int minSpecial;
	int minDigit;
	int minLower;
	int minUpper;
};


/**
 * @brief All needed variables to give to each thread
 */
@@ -218,26 +196,6 @@ public:
	inline uint64_t getNbSecurePasswords() const { return _sr.nbSecurePassword; }
	inline const IntOccurrence& getStatsLength() const { return stats_length; }
	inline const StringOccurrence& getStatsCharsets() const { return stats_charactersets; }
	static const std::string getCharset(const Policy& policy);
	static std::map<int, std::string> charsetNames() {
		std::map<int, std::string> names;
		names[1] = "numeric";
		names[2] = "loweralpha";
		names[3] = "loweralphanum";
		names[4] = "upperalpha";
		names[5] = "upperalphanum";
		names[6] = "mixedalpha";
		names[7] = "mixedalphanum";
		names[8] = "special";
		names[9] = "specialnum";
		names[10]= "loweralphaspecial";
		names[11]= "loweralphaspecialnum";
		names[12]= "upperalphaspecial";
		names[13]= "upperalphaspecialnum";
		names[14]= "mixedalphaspecial";
		names[15]= "all";
		return names;
	}

private:
	std::string filename;
+2 −26
Original line number Diff line number Diff line
@@ -21,9 +21,6 @@
#include "utils.h"
using namespace std;

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


Statsgen::Statsgen(const std::string& name) {
	if (name == "-"){
		is_stdin = true;
@@ -256,10 +253,6 @@ void Statsgen::print_stats() {
}






void analyse_letter(const char & letter, char & last_simplemask, string & simplemask_string, string & advancedmask_string, Policy & policy, int & sizeAdvancedMask, int & sizeSimpleMask) {
	sizeAdvancedMask++;

@@ -302,19 +295,6 @@ void analyse_letter(const char & letter, char & last_simplemask, string & simple
	}
}


const string Statsgen::getCharset(const Policy& p) {
	int charset = 0;
	charset ^= (bool) p.digit << 0;
	charset ^= (bool) p.lower << 1;
	charset ^= (bool) p.upper << 2;
	charset ^= (bool) p.special << 3;

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


Container analyze_password(const string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask) {
	Container c;
	c.pass_length = password.size();
@@ -327,13 +307,9 @@ Container analyze_password(const string & password, SecurityRules & sr, const in
		analyse_letter(letter, last_simplemask, c.simplemask_string, c.advancedmask_string, c.pol, sizeAdvancedMask, sizeSimpleMask);
	}

	c.characterset = Statsgen::getCharset(c.pol);
	c.characterset = c.pol;

	if ( (c.pass_length >= sr.minLength) &&
		 (c.pol.digit >= sr.minDigit) &&
		 (c.pol.lower >= sr.minLower) &&
		 (c.pol.upper >= sr.minUpper) &&
		 (c.pol.special >= sr.minSpecial) ) {
	if(c.pol.satisfies(sr, password.size())){
		sr.nbSecurePassword++;
	}