1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
bool CDlgIdentification::Verification(CString ident, CString passwd){
//Faire la vérification de l'identifiant et du mot de passe
std::ifstream fichier( "C:\\Temp\\passe.bin");
int truc;
if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
{
//CString ligne;
std::string ligne; // variable contenant chaque ligne lue
while ( std::getline( fichier, ligne ) ){
CCryptString OCrypt;
CString passwddec;
passwddec.GetBufferSetLength(ligne.length());
OCrypt.DecryptString((TCHAR*)ligne.c_str(), passwddec.GetBuffer(),cryptkey); //décrypter la ligne lue
CString Cligne = ligne.c_str();//copier le string en CString
CString CligneTemp = Cligne;
char* pWord= (char*)(malloc((sizeof(char*)*(passwddec.GetLength()))+1));
pWord = strtok(passwddec.GetBuffer(), ";");
while (pWord !=NULL){
//Comparer avec l'identifiant pour le premier
string basicstring(pWord);
if (ident == pWord){
//Si c'est bon, on vérifie le mot de passe
int i = 1;
pWord = strtok(NULL, ";");
if (passwd == pWord){
i = 2;
pWord = strtok(NULL,";");
compte.droit=pWord;
truc = 1;
return TRUE;
}
}
//Sinon, ligne suivante
break;
}
CligneTemp.ReleaseBuffer();
}
truc = 2;
ligne.~basic_string();
return FALSE; //On a parcouru tout le fichier sans trouver le bon
}
truc = 3; //Ouverture du fichier ratée
return FALSE;
} |