Generateur de mot de passe avec interface qt 4.4.3

Description

voici l'amélioration de mon générateur de mot de passe que j'avais posté et codé en c++ (console)
j'ai créer l'interface avec qt et j'ai apporter quelques améliorations au code de départ

vous pouvez créer des mots de passe avec des majuscules, des minuscules, des chiffre, des caractères spéciaux.
vous pouvez également créer un mot de passe en utilisant votre nom et prénom.

Source / Exemple :


FenCodeGenere.h:

#ifndef HEADER_FENCODEGENERE
#define HEADER_FENCODEGENERE

#include <QtGui>

class FenCodeGenere : public QDialog
{
	public:
		FenCodeGenere(QString &code, QWidget *parent);

	private:
		QLabel *proposition;
        QTextEdit *codeGenere;
        QPushButton *fermer;
};

#endif

FenGenereCode.cpp :

#include "FenCodeGenere.h"

FenCodeGenere::FenCodeGenere(QString &code, QWidget *parent = 0) : QDialog(parent)
{
	proposition = new QLabel("Proposition de MDP : \n~~~~~~~~~~~~");
	proposition->setFont(QFont("digital",12));
    codeGenere = new QTextEdit();
	codeGenere->setStyleSheet("background-color: rgb(236, 201, 248)");
    codeGenere->setPlainText(code);
    codeGenere->setReadOnly(true);
    codeGenere->setFont(QFont("Courier", 16, QFont::Bold));
    codeGenere->setLineWrapMode(QTextEdit::NoWrap);

    fermer = new QPushButton("Fermer");
	fermer->setFont(QFont("digital", 12, QFont::Bold));
	fermer->setStyleSheet("background-color: rgb(236, 201, 248)");

    QVBoxLayout *layoutPrincipal = new QVBoxLayout;
	layoutPrincipal->addWidget(proposition);
    layoutPrincipal->addWidget(codeGenere);
    layoutPrincipal->addWidget(fermer);

    resize(700, 450);
    setLayout(layoutPrincipal);

    connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));
}

fenetre.h:

#ifndef HEADER_FENETRE
#define HEADER_FENETRE

#include <QtGui>

class Fenetre : public QWidget
{
    Q_OBJECT

	public:
        Fenetre();

	public slots:
		void ouvrirAbout();
		void genererCode();
		void personnaliser();
		void Aide();

    private:
		QFormLayout *layoutNom;
		QLineEdit *nom, *prenom;
		QLabel *label, *nbCaract, *space, *space2;
		QRadioButton *min, *maj, *num, *spe, *mix, *utilis, *utilis_2;
		QPushButton *generer, *m_quitter, *m_about, *perso, *aide;
		QVBoxLayout *layoutChoix, *layoutLabel, *layoutCaractere, *layoutPrincipal;
		QHBoxLayout *layoutGenerer, *boutonsLayout, *layoutSpace, *layoutSpace2;
		QGroupBox *box, *boxCaractere, *utilisateur;
		
};

#endif

fenetre.cpp :

#include <iostream>
#include <ctime>

#include "Fenetre.h"
#include "FenCodeGenere.h"

using namespace std;
int loop=0;
QString code;

Fenetre::Fenetre() : QWidget()
{
	setWindowIcon(QIcon("prog.bmp"));
	setWindowTitle("MDP Générator");
	setFont(QFont("digital", 12));
	setStyleSheet("background-color: rgb(192,186,252)");//236,201,248 ou 247,228,252
	
	
	//layout principal
	layoutPrincipal = new QVBoxLayout;

	layoutNom = new QFormLayout;
	nom = new QLineEdit;
	nom->setStyleSheet("background-color: rgb(236, 201, 248)");
	nom->setFont(QFont("Digital", 12));
	prenom = new QLineEdit;
	prenom->setStyleSheet("background-color: rgb(236, 201, 248)");
	prenom->setFont(QFont("Digital", 12));
	layoutNom->addRow("&Nom :", nom);
	layoutNom->addRow("&Prenom :", prenom);
	utilisateur = new QGroupBox("&Utilisateur :");
	utilisateur->setLayout(layoutNom);
	
	//1er layout : presentation du produit
	label = new QLabel("<strong>Générateur de mot de passe</strong> !<br />Codé par <strong>Micmic</strong> !<br />Version 2.0", this);
	label->setAlignment(Qt::AlignCenter);
	
	//2eme layout : choix
	box = new QGroupBox("Que voulez-vous &utiliser ?");
	
	//sous layout : radiobutton
	layoutChoix = new QVBoxLayout;
	
	utilis = new QRadioButton("mot de passe avec des lettres de votre nom, prénom et des caractères spéc&iaux");
	utilis_2 = new QRadioButton("mot de passe avec 3 lettres de votre nom, de votre prénom et un nombre");
	maj = new QRadioButton("mot de passe n'utilisant que des &majuscules");
	min = new QRadioButton("mot de passe n'utilisant que des m&inuscules");
	num = new QRadioButton("mot de passe n'utilisant que des &chiffres");
	spe = new QRadioButton("mot de passe n'utilisant que des caractères &spéciaux");
	mix = new QRadioButton("m&ot de passe utilisant des majuscules, minuscules, des chiffres\net des caractères spéciaux");

	utilis->setChecked(true);
	
	layoutChoix -> addWidget(utilis);
	layoutChoix -> addWidget(utilis_2);
	layoutChoix -> addWidget(maj);
	layoutChoix -> addWidget(min);
	layoutChoix -> addWidget(num);
	layoutChoix -> addWidget(spe);
	layoutChoix -> addWidget(mix);

	box->setLayout(layoutChoix);

	layoutLabel = new QVBoxLayout;
	
	nbCaract = new QLabel("<strong><br />Le programme va générer des mots de passe <br />"
		"de la longueur que vous préciserez ci dessous</strong><br />", this);
	layoutLabel->addWidget(nbCaract);
	nbCaract->setAlignment(Qt::AlignCenter);
	
	boxCaractere = new QGroupBox("Nombe de caractères pour votre mot de passe :");//contenant spinbox et Qlabel
	layoutCaractere = new QVBoxLayout; // layout contenant la spinbox
	
	perso = new QPushButton("&Personnaliser le nombre de caractères");	
	perso->setToolTip("choisir le nombre de caractère pour le mot de passe");
	perso->setFont(QFont("digital", 12));
	perso->setStyleSheet("background-color: rgb(236, 201, 248)");
	
	layoutCaractere->addSpacing(10);
	layoutCaractere->addWidget(perso);

	boxCaractere->setLayout(layoutCaractere);	

	layoutSpace = new QHBoxLayout;
	space = new QLabel("Le programme va vous proposer 10 mots de passe differents<br />");
	space->setAlignment(Qt::AlignCenter);
	layoutSpace ->addWidget(space);

	layoutGenerer = new QHBoxLayout;
	generer = new QPushButton ("&GENERER");
	generer->setFont(QFont("digital", 16));
	generer->setStyleSheet("background-color: rgb(236, 201, 248)");
    generer->setCursor(Qt::PointingHandCursor);
	generer->setToolTip("générer le mot de passe");
	layoutGenerer->addWidget(generer);

	layoutSpace2 = new QHBoxLayout;
	space2 = new QLabel("<br />");
	layoutSpace2->addWidget(space2);

	boutonsLayout = new QHBoxLayout;
	
	m_about = new QPushButton ("A &Propos");
	m_about->setToolTip("à propos");
	m_about->setFont(QFont("digital", 14));
	m_about->setStyleSheet("background-color: rgb(236, 201, 248)");

	aide = new QPushButton("&Aide");
	aide->setToolTip("aide");
	aide->setFont(QFont("digital", 14));
	aide->setStyleSheet("background-color: rgb(236, 201, 248)");

	m_quitter = new QPushButton( "&Quitter");
	m_quitter->setToolTip("Quitter");
	m_quitter->setFont(QFont("digital", 14));
	m_quitter->setStyleSheet("background-color: rgb(236, 201, 248)");
	
	boutonsLayout->addWidget(m_about);
	boutonsLayout->addWidget(aide);
	boutonsLayout->addWidget(m_quitter);

	layoutPrincipal->addWidget(label);
	layoutPrincipal->addWidget(utilisateur);
	layoutPrincipal->addWidget(box);
	layoutPrincipal->addWidget(nbCaract);
	layoutPrincipal->addWidget(boxCaractere);
	layoutPrincipal->addLayout(layoutSpace);
	layoutPrincipal->addLayout(layoutGenerer);
	layoutPrincipal->addLayout(layoutSpace2);
	layoutPrincipal->addLayout(boutonsLayout);

	setLayout(layoutPrincipal);

	QObject::connect(m_quitter, SIGNAL(clicked()), qApp, SLOT(quit()));
	QObject::connect(m_about, SIGNAL(clicked()), this, SLOT(ouvrirAbout()));
	QObject::connect(aide, SIGNAL(clicked()), this, SLOT(Aide()));
	QObject::connect(generer, SIGNAL(clicked()), this, SLOT(genererCode()));
	QObject::connect(perso, SIGNAL(clicked()), this, SLOT(personnaliser()));
	  
}

void Fenetre::ouvrirAbout()
{
		
		QMessageBox::about(this,"MDP Générator", "Merci d'utiliser <strong>MDP Générator</strong>"
		"<br /><br />MDP Générator est un Générateur de mot de passe, "
		"<br />Développé par Micmic : codé en c++ avec une interface produite avec Qt"
		"<br />Version 2.0, codé le 12 Janvier 2009 !"
		"<br /><br />vous pouvez générer des mots de passe, des clés WEP, WAP, de cryptage,etc....      ");
		setFont(QFont("digital", 12));
}

void Fenetre::genererCode()
{
	srand(time(NULL));
	//QString code;
	if(nom->text().isEmpty() || prenom->text().isEmpty())
	{
		QMessageBox::critical(this, "Erreur", "Veuillez entrer un nom et un prénom");
		return;
	}
	
	if(loop ==0)
	{
		QMessageBox::critical(this,"MDP Générator", "vous devez d'abord choisir le nombre de caractères");
		return;
	}

	else
	{
		if(utilis ->isChecked())
		{
			const char spe[] = {'&', '~', '#', 'ç', '@', '£', '$', '%', 'µ', '§'};  // max = 9
			int MAX =9, MIN=1;
			
			QString str_nom = nom->text();
			int n_max = str_nom.size();
			QString str_prenom = prenom->text();
			int p_max = str_prenom.size();
			
			if (loop ==3)
			{
				for (int i=0; i < 10; i++)
				{
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +="\n";
				}
			}
			else if(loop == 4)
			{
				for (int i=0; i < 10; i++)
				{
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +=spe[(rand() % (MAX - MIN + 1)) + MIN];
					code +="\n";
				}
			}
			else if (loop == 5)
				{
				for (int i=0; i < 10; i++) 
				{
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +=spe[(rand() % (MAX - MIN + 1)) + MIN];
					code +="\n";
				}
			}
			else if (loop == 6)
				{
				for (int i=0; i < 10; i++)
				{
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +=spe[(rand() % (MAX - MIN + 1)) + MIN];
					code +="\n";
				}
			}
			else if (loop == 7)
				{
				for (int i=0; i < 10; i++)
				{
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +=spe[(rand() % (MAX - MIN + 1)) + MIN];
					code +="\n";
				}
			}
			else if (loop == 8)
				{
				for (int i=0; i < 10; i++) 
				{
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +=spe[(rand() % (MAX - MIN + 1)) + MIN];
					code +="\n";
				}
			}
			else if (loop == 9)
				{
				for (int i=0; i < 10; i++)
				{
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +=spe[(rand() % (MAX - MIN + 1)) + MIN];
					code +="\n";
				}
			}
			else if (loop == 10)
			{
				for (int i=0; i < 10; i++)
				{
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += str_nom[(rand() % ((n_max-1) - MIN +1)) + MIN];
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code += str_prenom[(rand() % ((p_max-1) - MIN +1)) + MIN];
					code +=spe[(rand() % (MAX - MIN + 1)) + MIN];
					code +=" ";
					code +="\n";
				}
			}
			
		}
		else if (utilis_2 -> isChecked())
		{
			QString str2_nom = nom->text();
			QString str2_prenom = prenom->text();
			int min_num =1900, max_num = 2010;
			int n_max =10, n_min =0;
			int hasard = ((rand () % (n_max - n_min +1)) - n_min);
			if ((hasard%2)==0)
			{
				for (int i=0; i < 10; i++)
				{

					code += str2_nom[0];
					code += str2_nom[1];
					code += str2_nom[2];
					code += "_";
					code += str2_prenom[0];
					code += str2_prenom[1];
					code += str2_prenom[2];
					code += QString ::number (int((rand() % (max_num - min_num +1)) + min_num), 10);
					code +=" ";
					code += "\n";
				}
				code += "\n";
			}
			else
				{
				for (int i=0; i < 10; i++)
				{

					code += str2_prenom[0];
					code += str2_prenom[1];
					code += str2_prenom[2];
					code += "_";
					code += str2_nom[0];
					code += str2_nom[1];
					code += str2_nom[2];
					code += QString ::number (int((rand() % (max_num - min_num +1)) + min_num), 10);
					code +=" ";
					code += "\n";
				}
				code += "\n";
			}

		}

		else if (maj ->isChecked())
		{
			int MAX = 25, MIN =1;
			const char maj[] = {'A', 'B', 'C', 'D','E', 'F', 'G', 'H', 'I', 'J',  // max = 25
							'K', 'L', 'M', 'N','O', 'P', 'Q', 'R', 'S', 'T',
							'U', 'V', 'W', 'X',	'Y', 'Z'};
	
			for (int j=0; j<10; j++)
			{
				code+="\t";
				for (int i=0; i < loop; i++)
				{
					code += maj[(rand() % (MAX - MIN + 1)) + MIN];
					code += " ";
				}
				code += "\n";
			}
		}
		else if (min->isChecked())
		{
			int MAX = 25, MIN =1;
			const char min[] = {'a','b', 'c', 'd', 'e','f', 'g', 'h', 'i', 'j',  // max = 25
							'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
							'u', 'v', 'w', 'x', 'y', 'z'};
			for (int j=0; j<10; j++)
			{
				code+="\t";
				for (int i=0; i < loop; i++)
				{
					code += min[(rand() % (MAX - MIN + 1)) + MIN];
					code += " ";
				}
				code += "\n";
			}
		}
		else if(num->isChecked())
		{
			int MAX = 9, MIN =1;
			const char num[] = {'0', '1', '2', '3','4', '5', '6', '7', '8', '9'}; // max = 9
	
			for (int j=0; j<10; j++)
			{			
				code+="\t";
				for (int i=0; i < loop; i++)
				{
					code += num[(rand() % (MAX - MIN + 1)) + MIN];
					code += " ";
				}
				code += "\n";
			}
		}
		else if(spe->isChecked())
		{
			int MAX = 9, MIN =1;
			const char spe[] = {'&', '~', '#', 'ç', '@', '£', '$', '%', 'µ', '§'};  // max = 9
	
			for (int j=0; j<10; j++)
			{		
				code+="\t";
				for (int i=0; i < loop; i++)
				{
					code += spe[(rand() % (MAX - MIN + 1)) + MIN];
					code += " ";
				}
				code += "\n";
			}
		}
		else if(mix->isChecked())
		{
			int MAX = 70, MIN =1;
			const char mix[] = {'a','b', 'c', 'd', 'e','f', 'g', 'h', 'i', 'j',    // max = 70
							'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
							'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
							'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
							'O', 'P', 'Q', 'R', 'S', 'T','U', 'V', 'W', 'X',
							'Y', 'Z', '0', '1', '2', '3','4', '5', '6', '7',
							'8', '9', '&', '~', '#', 'ç', '@', '£', '$', '%', 
							'µ', '§'};
			for (int j=0; j<10; j++)
			{			
				code+="\t";
				for (int i=0; i < loop; i++)
				{
					code += mix[(rand() % (MAX - MIN + 1)) + MIN];
					code += " ";
				}
				code += "\n";
			}
		}
			

	FenCodeGenere *fenetreCode = new FenCodeGenere(code, this);
	fenetreCode->exec();
	}
}

void Fenetre::personnaliser()
{
	if (utilis->isChecked())
	{
		bool ok;
	    int i = QInputDialog::getInteger(this, tr("Personnaliser le mot de passe"),
			tr("nombre de caracteres:"), 1, 3, 10, 1, &ok);
		loop = i;
	}
	else if (utilis_2->isChecked())
	{
		bool ok;
	    int i = QInputDialog::getInteger(this, tr("Personnaliser le mot de passe"),
			tr("nombre de caracteres fixé à:"), 1, 10, 10, 1, &ok);
		loop = i;
	}
	else if( maj->isChecked() || min->isChecked() || num->isChecked() || spe->isChecked() || mix->isChecked())
	{
		bool ok;
	    int i = QInputDialog::getInteger(this, tr("Personnaliser le mot de passe"),
			tr("nombre de caracteres:"), 1, 1, 50, 1, &ok);
		loop = i;
	}
}

void Fenetre::Aide()
{
	QMessageBox::about(this,"MDP Générator", "Merci d'utiliser <strong>MDP Générator</strong>"
		"<br /><br />1- Vous devez cocher une case pour choisir les caracteres désirés"
		"<br />2- Cliquer sur \"Personnaliser le nombre de caracteres\""
		"<br />3- choisir le nombre dans la fenetre ouverte en cliquant sur les fleches haut et bas"
		"<br />4- Cliquer sur générer pour decouvrir les propositions de mot de passe");

}

main.cpp :

#include <QApplication>
#include "Fenetre.h"

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

	QString locale = QLocale::system().name();
    QTranslator translator;
    translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&translator);

    Fenetre fenetre;
    fenetre.show();

    return app.exec();
}

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.

Du même auteur (micmic92)