Skip to content

Commit

Permalink
Update validation.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Josseye authored Feb 15, 2024
1 parent 4c68de5 commit dab058e
Showing 1 changed file with 1 addition and 71 deletions.
72 changes: 1 addition & 71 deletions homework/password-check/validation.hpp
Original file line number Diff line number Diff line change
@@ -1,71 +1 @@
#pragma once
#include <iostream>
#include <string>
#include <cctype>
enum class Error {
Ok,
PasswordNeedsAtLeastNineCharacters,
PasswordNeedsAtLeastOneNumber,
PasswordNeedsAtLeastOneSpecialCharacter,
PasswordNeedsAtLeastOneUppercaseLetter,
PasswordsDoNotMatch
};

std::string getErrorMessage(int errcode) {
switch (errcode) {
case 0:
return "Ok";
case 1:
return "Password Needs AtLeast Nine Characters";
case 2:
return "Password Needs AtLeast OneNumber";
case 3:
return "Password Needs AtLeast One Special Character";
case 4:
return "Password Needs AtLeast One Uppercase Letter";
case 5:
return "Passwords Do Not Match";
}
}

bool doPasswordsMatch(std::string psw1, std::string psw2) {
if (psw1 == psw2)
return true;
else
return false;
}

int checkPasswordRules(std::string pass) {
int i;
Error back;
bool OneNumber, OneUppercaseLetter, OneSpecialCharacter;
OneNumber = false;
OneUppercaseLetter = false;
OneSpecialCharacter = false;
if (pass.length()<9)
return static_cast <int>(back = Error::PasswordNeedsAtLeastNineCharacters);
for (auto element : pass) {
if (isdigit(element))
OneNumber = true;
if (!isalnum(element))
OneSpecialCharacter = true;
if (isupper(element))
OneUppercaseLetter = true;
}
if (!OneNumber)
return static_cast <int>(back = Error::PasswordNeedsAtLeastOneNumber);
else
if (!OneUppercaseLetter)
return static_cast <int>(back = Error::PasswordNeedsAtLeastOneUppercaseLetter);
else
if (!OneSpecialCharacter)
return static_cast <int>(back = Error::PasswordNeedsAtLeastOneSpecialCharacter);
else return static_cast <int>(back = Error::Ok);
}

int checkPassword(std::string firstpassword, std::string secondpassword) {
if (!doPasswordsMatch(firstpassword, secondpassword))
return static_cast<int>(Error::PasswordsDoNotMatch);
else
return checkPasswordRules(firstpassword);
}
///

0 comments on commit dab058e

Please sign in to comment.