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

some cleanup

parent 33d4263b
Loading
Loading
Loading
Loading
+28 −20
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <iostream>
#include <regex>
#include <queue>
#include <thread>

#define MAX_THREADS 32

@@ -126,65 +127,75 @@ public:
	 * @brief useful to hide statistics below 1%
	 * @param hr: 1 to hide, else 0
	 */
	void setHiderare(int hr);
	inline void setHiderare(const int& hr) { hiderare = hr; }

	/**
	 * @brief Defining the number of best results the user wants to see,
	 * and so the result should be clearer
	 * @param t: number of interesting results
	 */
	void setTop(int t);
	inline void setTop(const int& t) { top = t; }

	/**
	 * @brief Defining a regular expression to analyse only
	 * some interesting passwords
	 * @param reg: regular expression
	 */
	void setRegex(const std::string& reg);
	inline void setRegex(const std::string& reg) {
		current_regex = reg;
		use_regex = true;
	}

	/**
	 * @brief Useful to know if the database uses the format withcount
	 * @param var: true if database uses the format withcount, else false
	 */
	void setWithcount(bool var);
	inline void setWithcount(const bool& wc) { withcount = wc; }

	/**
	 * @brief Filter for the size of the simple masks, can be
	 * used as an optimisation option
	 * @param limit: number that limit the size of the simple masks
	 */
	void setLimitSimplemask(int limit);
	inline void setLimitSimplemask(const int& limit) { limitSimplemask = limit; }

	/**
	 * @brief Filter for the size of the advanced masks, can be
	 * used as an optimisation option
	 * @param limit: number that limit the size of the advanced masks
	 */
	void setLimitAdvancedmask(int limit);
	inline void setLimitAdvancedmask(const int& limit) { limitAdvancedmask = limit; }

	/**
	 * @brief Number of threads the user wants to use
	 * @param nb: number of usable threads
	 */
	void setNbThread(int nb);
	inline void setNbThread(const int& nb) {
		int max = std::thread::hardware_concurrency();
		if (nb > max) {
			nbThread = max;
		} else {
			nbThread = nb;
		}
	}


	/**
	 * @brief Defining all security rules
	 */
	void setSecurityRules();
	void setSecurityRules(int length,int special,int digit,int upper,int lower);
	void askSecurityRules();
	void setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower);

	/**
	 * @brief Where to write masks
	 * @param outfile: the file where to write masks
	 */
	void setOutfile(const std::string& outfile);
	inline void setOutfile(const std::string& outfile) { outfile_name = outfile; }

	/**
	 * @brief enable debugging
	 */
	void enableDebug();
	inline void enableDebug() { debug_enabled = true; }

	/**
	 * @brief print the warning message
@@ -210,14 +221,11 @@ public:
	 */
	void print_stats();

	uint64_t getTotalCounter();
	uint64_t getTotalFilter();
	uint64_t getNbSecurePasswords();
	IntOccurrence getStatsLength();
	StringOccurrence getStatsCharsets();



	inline uint64_t getTotalCounter() const { return total_counter; }
	inline uint64_t getTotalFilter() const { return total_filter; }
	inline uint64_t getNbSecurePasswords() const { return nbSecurePassword; }
	inline const IntOccurrence& getStatsLength() const { return stats_length; }
	inline const StringOccurrence& getStatsCharsets() const { return stats_charactersets; }

private:
	std::string filename;
@@ -293,7 +301,7 @@ void analyse_charset(std::string & charset, const Policy & policy);
 * @param limitAdvancedmask: define the limit for the size of advanced masks
 * @param limitSimplemask: define the limit for the size of simple masks
 */
Container analyze_password(const std::string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask);
// Container analyze_password(const std::string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask);

/**
 * @brief Update minima and maxima of all general data from analysed passwords
+1 −1
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ int main(int argc,char* argv[]) {
			case 'p':
				statsgen.setNbThread(atoi(optarg)); break;
			case 's':
				statsgen.setSecurityRules(); break;
				statsgen.askSecurityRules(); break;
			default:
				showHelp(); break;
		}
+20 −88
Original line number Diff line number Diff line
@@ -35,54 +35,6 @@ Statsgen::Statsgen(const std::string& name) {
	}
}

void Statsgen::setHiderare(int val) {
	hiderare = val;
}



void Statsgen::setTop(int val) {
	top = val;
}


void Statsgen::setRegex(const string& expr) {
	current_regex = string(expr);
	use_regex = true;
}


void Statsgen::setWithcount(bool val) {
	withcount = val;
}


void Statsgen::setLimitSimplemask(int val) {
	limitSimplemask = val;
}

void Statsgen::setLimitAdvancedmask(int val) {
	limitAdvancedmask = val;
}


void Statsgen::setNbThread(int nb) {
	int max = thread::hardware_concurrency();
	if (nb > max) {
		nbThread = max;
	} else {
		nbThread = nb;
	}
}

void Statsgen::setOutfile(const string& outfile){
	outfile_name = outfile;
}

void Statsgen::enableDebug(){
	debug_enabled = true;
}

void Statsgen::warn(const char* messages...){
	va_list args;
	va_start(args, messages);
@@ -121,7 +73,7 @@ void Statsgen::debug(const char* messages...){
}


void Statsgen::setSecurityRules() {
void Statsgen::askSecurityRules() {
	wcout << "\nMinimal length of a password:" << endl;
	cin >> minLength;

@@ -138,7 +90,7 @@ void Statsgen::setSecurityRules() {
	cin >> minUpper;
}

void Statsgen::setSecurityRules(int length,int special,int digit,int upper,int lower) {
void Statsgen::setSecurityRules(const int& length, const int& special, const int& digit, const int& upper, const int& lower) {
    minLength = length;
    minSpecial = special;
    minDigit = digit;
@@ -403,7 +355,7 @@ void analyse_letter(const char & letter, char & last_simplemask, string & simple
}


string analyse_charset(const Policy & policy) {
const string analyse_charset(const Policy & policy) {
	string charset;
	if (policy.digit && !policy.lower && !policy.upper && !policy.special) {
		charset = "numeric";
@@ -493,33 +445,33 @@ Container analyze_password(const string & password, SecurityRules & sr, const in



void updateMinMax(minMax & minMaxValue, const Policy & pol) {
	if (minMaxValue.mindigit == -1 || minMaxValue.mindigit > pol.digit) {
		minMaxValue.mindigit = pol.digit;
void updateMinMax(minMax & m, const Policy & pol) {
	if (m.mindigit == -1 || m.mindigit > pol.digit) {
		m.mindigit = pol.digit;
	}
	if (minMaxValue.maxdigit == -1 || minMaxValue.maxdigit < pol.digit) {
		minMaxValue.maxdigit = pol.digit;
	if (m.maxdigit == -1 || m.maxdigit < pol.digit) {
		m.maxdigit = pol.digit;
	}

	if (minMaxValue.minlower == -1 || minMaxValue.minlower > pol.lower) {
		minMaxValue.minlower = pol.lower;
	if (m.minlower == -1 || m.minlower > pol.lower) {
		m.minlower = pol.lower;
	}
	if (minMaxValue.maxlower == -1 || minMaxValue.maxlower < pol.lower) {
		minMaxValue.maxlower = pol.lower;
	if (m.maxlower == -1 || m.maxlower < pol.lower) {
		m.maxlower = pol.lower;
	}

	if (minMaxValue.minupper == -1 || minMaxValue.minupper > pol.upper) {
		minMaxValue.minupper = pol.upper;
	if (m.minupper == -1 || m.minupper > pol.upper) {
		m.minupper = pol.upper;
	}
	if (minMaxValue.maxupper == -1 || minMaxValue.maxupper < pol.upper) {
		minMaxValue.maxupper = pol.upper;
	if (m.maxupper == -1 || m.maxupper < pol.upper) {
		m.maxupper = pol.upper;
	}

	if (minMaxValue.minspecial == -1 || minMaxValue.minspecial > pol.special) {
		minMaxValue.minspecial = pol.special;
	if (m.minspecial == -1 || m.minspecial > pol.special) {
		m.minspecial = pol.special;
	}
	if (minMaxValue.maxspecial == -1 || minMaxValue.maxspecial < pol.special) {
		minMaxValue.maxspecial = pol.special;
	if (m.maxspecial == -1 || m.maxspecial < pol.special) {
		m.maxspecial = pol.special;
	}
}

@@ -631,26 +583,6 @@ void * generate_stats_thread(void * threadarg) {
	pthread_exit(NULL);
}

uint64_t Statsgen::getTotalCounter() {
	return total_counter;
}

uint64_t Statsgen::getTotalFilter() {
	return total_filter;
}

uint64_t Statsgen::getNbSecurePasswords() {
	return nbSecurePassword;
}

IntOccurrence Statsgen::getStatsLength(){
	return stats_length;
}

StringOccurrence Statsgen::getStatsCharsets(){
	return stats_charactersets;
}


uint64_t nbline_file(const string & filename) {
	ifstream readfile(filename);
+4 −4
Original line number Diff line number Diff line
@@ -9,15 +9,15 @@
 * Please see the attached LICENSE file for additional licensing information.
 */

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "utils.h"

#include <QFileDialog>
#include <QTextStream>
#include <iostream>
#include <QtCharts>

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "utils.h"

using namespace std;

MainWindow::MainWindow(QWidget *parent) :