Skip to content
Snippets Groups Projects
Commit 6b13e0ab authored by Mathieu Valois's avatar Mathieu Valois
Browse files

Remove useless doc, move some functions and force some other const

parent 8cd16f4a
No related branches found
No related tags found
No related merge requests found
Pipeline #6334 passed
......@@ -38,88 +38,24 @@ public:
Statsgen(){}
Statsgen(const std::string& name);
/**
* @brief useful to hide statistics below 1%
* @param hr: 1 to hide, else 0
*/
inline void setHiderare(const int& hr) { hiderare = hr; }
int generate_stats();
void print_stats() const;
/**
* @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
*/
inline void setHiderare(const int& hr) { hiderare = hr; }
inline void setTop(const int& t) { top = t; }
/**
* @brief Defining a regular expression to analyse only
* some interesting passwords
* @param reg: regular expression
*/
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
*/
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
*/
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
*/
inline void setLimitAdvancedmask(const int& limit) { limitAdvancedmask = limit; }
/**
* @brief Number of threads the user wants to use
* @param nb: number of usable threads
*/
inline void setNbThread(const int& nb) { nbThread = nb; }
void configureThread(ThreadData& td) const;
/**
* @brief Defining all security rules
*/
void askSecurityRules();
void setSecurityRules(const uint& length, const uint& special, const uint& digit, const uint& upper, const uint& lower);
/**
* @brief Where to write masks
* @param outfile: the file where to write masks
*/
inline void setOutfile(const std::string& outfile) { outfile_name = outfile; }
/**
* @brief enable debugging
*/
inline void enableDebug() { debug_enabled = true; }
/**
* @brief Calculate all statistics for a database
* @return 0 if error, 1 if success
*/
int generate_stats();
/**
* @brief Print all calculated statistics
*/
void print_stats();
inline int getNbThreads() const { return nbThread; }
inline uint64_t getNbLines() const { return nblines; }
inline uint64_t getProcessed() const { return processed; }
......@@ -127,7 +63,6 @@ public:
inline bool allFinished() const { return finished; }
inline bool allStarted() const { return started; }
bool operator==(const Statsgen& other) const;
void handle_password(const std::string& password, const uint64_t& nbPasswords, ThreadData& td) const;
private:
std::string filename;
......@@ -157,6 +92,9 @@ private:
uint finished = false;
// all threads have been started
bool started = false;
void handle_password(const std::string& password, const uint64_t& nbPasswords, ThreadData& td) const;
std::pair<uint, uint> get_masks(const std::string& password, PasswordStats& c) const;
};
#endif
......@@ -61,6 +61,24 @@ void showHelp() {
exit(EXIT_SUCCESS);
}
void askSecurityRules(Statsgen& stats){
uint length, special, digit, upper, lower;
cout << "Minimal length of a password:" << endl;
cin >> length;
cout << "Minimum of special characters in a password:" << endl;
cin >> special;
cout << "Minimum of digits in a password:" << endl;
cin >> digit;
cout << "Minimum of lower characters in a password:" << endl;
cin >> lower;
cout << "Minimum of upper characters in a password:" << endl;
cin >> upper;
stats.setSecurityRules(length, special, digit, upper, lower);
}
int main(int argc,char* argv[]) {
locale::global(locale(""));
......@@ -128,7 +146,7 @@ int main(int argc,char* argv[]) {
return EXIT_FAILURE;
}
if(arg == "-s" || arg == "--security"){
statsgen.askSecurityRules(); continue;
askSecurityRules(statsgen); continue;
}
else {
unknownArg(argv[i]);
......
......@@ -23,26 +23,6 @@ using namespace std;
Statsgen::Statsgen(const std::string& name):filename(name){}
void Statsgen::askSecurityRules() {
uint length, special, digit, upper, lower;
cout << "Minimal length of a password:" << endl;
cin >> length;
cout << "Minimum of special characters in a password:" << endl;
cin >> special;
cout << "Minimum of digits in a password:" << endl;
cin >> digit;
cout << "Minimum of lower characters in a password:" << endl;
cin >> lower;
cout << "Minimum of upper characters in a password:" << endl;
cin >> upper;
setSecurityRules(length, special, digit, upper, 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 };
}
......@@ -109,7 +89,7 @@ int Statsgen::generate_stats() {
return 1;
}
void Statsgen::print_stats() {
void Statsgen::print_stats() const {
int count;
float perc = percentage(results.total_filter, results.total_counter);
......@@ -152,7 +132,10 @@ void Statsgen::print_stats() {
if (limitSimplemask > 0) {
cout << endl;
readResult(results.simplemasks["othermasks"], "othermasks", count, results.total_counter, hiderare);
auto r = results.simplemasks.find("othermasks");
if(r != results.simplemasks.end()){
readResult(r->second, r->first, count, results.total_counter, hiderare);
}
}
......@@ -172,12 +155,15 @@ void Statsgen::print_stats() {
if (limitAdvancedmask > 0) {
cout << endl;
readResult(results.advancedmasks["othermasks"], "othermasks", count, results.total_counter, hiderare);
auto r = results.advancedmasks.find("othermasks");
if(r != results.advancedmasks.end()){
readResult(r->second, r->first, count, results.total_counter, hiderare);
}
}
}
pair<uint, uint> get_masks(const string& password, PasswordStats& c){
pair<uint, uint> Statsgen::get_masks(const string& password, PasswordStats& c) const {
char last_simplemask = 'a';
uint sizeSimpleMask = 0;
uint sizeAdvancedMask = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment