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

Iteration over letters is done inside function

parent ca777cd8
No related branches found
No related tags found
No related merge requests found
Pipeline #6292 passed
......@@ -79,8 +79,8 @@ struct thread_data {
bool use_regex = false;
bool withcount = false;
int limitSimplemask;
int limitAdvancedmask;
uint limitSimplemask;
uint limitAdvancedmask;
SecurityRules sr;
......@@ -255,15 +255,6 @@ private:
*/
// void analyse_letter(const char & letter, char & last_simplemask, std::string & simplemask_string, std::string & advancedmask_string, Policy & policy, int & sizeAdvancedMask, int & sizeSimpleMask);
/**
* @brief Analyse a password
* @param password: current password
* @param c: container of all useful data of the password
* @param sr: get the actual security rules and count the number of password respecting them
* @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);
/**
* @brief Update minima and maxima of all general data from analysed passwords
......
......@@ -242,7 +242,11 @@ void Statsgen::print_stats() {
}
void analyse_letter(const char & letter, PasswordStats& c, char & last_simplemask, int & sizeAdvancedMask, int & sizeSimpleMask) {
pair<uint, uint> get_masks(const string& password, PasswordStats& c){
char last_simplemask = 'a';
uint sizeSimpleMask = 0;
uint sizeAdvancedMask = 0;
for(wchar_t letter: password){
sizeAdvancedMask++;
if (letter >= '0' && letter <= '9') {
......@@ -283,32 +287,7 @@ void analyse_letter(const char & letter, PasswordStats& c, char & last_simplemas
}
}
}
PasswordStats analyze_password(const string & password, SecurityRules & sr, const int & limitAdvancedmask, const int & limitSimplemask) {
PasswordStats c;
c.pass_length = password.size();
char last_simplemask = 'a';
int sizeAdvancedMask = 0;
int sizeSimpleMask = 0;
for(wchar_t letter: password){
analyse_letter(letter, c, last_simplemask, sizeAdvancedMask, sizeSimpleMask);
}
if(c.pol.satisfies(sr, password.size())){
sr.nbSecurePassword++;
}
if (sizeAdvancedMask > limitAdvancedmask) {
c.advancedmask_string = "othermasks";
}
if (sizeSimpleMask > limitSimplemask) {
c.simplemask_string = "othermasks";
}
return c;
return make_pair(sizeSimpleMask, sizeAdvancedMask);
}
void updateMinMax(minMax& m, const Policy& pol) {
......@@ -327,9 +306,23 @@ void handle_password(const string& password, const uint64_t& nbPasswords, thread
if(my_data->use_regex && !regex_match(password,my_data->current_regex)){
return;
}
PasswordStats c = analyze_password(password, my_data->sr,my_data->limitAdvancedmask, my_data->limitSimplemask);
PasswordStats c;
pair<uint, uint> masks = get_masks(password, c);
if(c.pol.satisfies(my_data->sr, password.size())){
my_data->sr.nbSecurePassword++;
}
if (masks.first > my_data->limitSimplemask) {
c.simplemask_string = "othermasks";
}
if (masks.second > my_data->limitAdvancedmask) {
c.advancedmask_string = "othermasks";
}
my_data->total_filter += nbPasswords;
my_data->length[ c.pass_length ] += nbPasswords;
my_data->length[ password.size() ] += nbPasswords;
my_data->charactersets[ c.pol ] += nbPasswords;
my_data->simplemasks[ c.simplemask_string ] += nbPasswords;
my_data->advancedmasks[ c.advancedmask_string ] += nbPasswords;
......@@ -399,7 +392,7 @@ uint64_t nbline_file(const string & filename) {
}
// we have not read the whole file
if (readfile.fail() && !readfile.eof()){
cerr << "[ERROR]" << " There was an error reading the file at line " << nb << endl;
cerr << "[ERROR] There was an error reading the file at line " << nb << endl;
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment