Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "usernamepasswordgenerator.h"
- #include "ui_usernamepasswordgenerator.h"
- #include <QClipboard>
- #include <QFileDialog>
- #include <QDebug>
- #include <cstdlib>
- #include <QTime>
- #include "global.h"
- #include <QMessageBox>
- const int sliderDefaultMax = 256;
- const int sliderDefaultMin = 1;
- const int sliderDefaultVal = 40;
- const int sliderMax = 1024;
- bool lowercase = false;
- bool uppercase = false;
- bool decimalNumbers = false;
- bool nonAlphaNumerical = false;
- bool ascii32To255 = false;
- UsernamePasswordGenerator::UsernamePasswordGenerator(QWidget *parent) : QDialog(parent), ui(new Ui::UsernamePasswordGenerator)
- {
- ui->setupUi(this);
- ui->horizontalSlider_2->setMaximum(sliderDefaultMax);
- ui->horizontalSlider_2->setMinimum(sliderDefaultMin);
- ui->horizontalSlider_2->setValue(sliderDefaultVal);
- ui->spinBox_5->setMaximum(sliderMax);
- ui->spinBox_5->setMinimum(sliderDefaultMin);
- ui->spinBox_5->setValue(sliderDefaultVal);
- ui->spinBox_4->setMaximum(sliderMax);
- ui->spinBox_4->setValue(sliderDefaultMax);
- ui->spinBox_6->setMinimum(sliderDefaultMin);
- ui->spinBox_6->setMaximum(sliderMax);
- ui->spinBox_6->setValue(sliderDefaultMin);
- ui->checkBox_6->setChecked(true);
- ui->checkBox_7->setChecked(true);
- ui->checkBox_9->setChecked(true);
- ui->checkBox_10->setChecked(true);
- ui->lineEdit_2->setEchoMode(QLineEdit::Password);
- ui->pushButton_11->setText("Hide");
- emit on_pushButton_8_clicked();
- return;
- }
- UsernamePasswordGenerator::~UsernamePasswordGenerator()
- {
- delete ui;
- return;
- }
- int UsernamePasswordGenerator::pullRandomNumber(int min1, int max1, int min2, int max2, int min3, int max3, int min4, int max4)
- {
- int returnValue = 0;
- int usedRanges = 4;
- int usedRange = 0;
- if(min1 == -1 || max1 == -1)
- {
- usedRanges--;
- min1 = min2;
- max1 = max2;
- min2 = min3;
- max2 = max3;
- min3 = min4;
- max3 = max4;
- }
- if(min2 == -1 || max2 == -1)
- {
- usedRanges--;
- min2 = min3;
- max2 = max3;
- min3 = min4;
- max3 = max4;
- }
- if(min3 == -1 || max3 == -1)
- {
- usedRanges--;
- min3 = min4;
- max3 = max4;
- }
- if(min4 == -1 || max4 == -1)
- {
- usedRanges--;
- }
- if(usedRanges <= 0)
- {
- returnValue = -1;
- }
- else
- {
- usedRange = rand() % usedRanges;
- switch(usedRange)
- {
- case 0:
- returnValue = getRandom() % ((max1 + 1) - min1) + min1;
- break;
- case 1:
- returnValue = getRandom() % ((max2 + 1) - min2) + min2;
- break;
- case 2:
- returnValue = getRandom() % ((max3 + 1) - min3) + min3;
- break;
- case 3:
- returnValue = getRandom() % ((max4 + 1) - min4) + min4;
- break;
- }
- }
- return returnValue;
- }
- int UsernamePasswordGenerator::getRandom()
- {
- return qrand();
- }
- void UsernamePasswordGenerator::setRandomSeed()
- {
- QTime time = QTime::currentTime();
- qsrand((uint)time.msec());
- return;
- }
- void UsernamePasswordGenerator::on_pushButton_6_clicked()
- {
- QClipboard *clipboard = QApplication::clipboard();
- clipboard->setText(ui->lineEdit_2->text());
- return;
- }
- void UsernamePasswordGenerator::on_pushButton_10_clicked()
- {
- QClipboard *clipboard = QApplication::clipboard();
- clipboard->setText(ui->lineEdit_3->text());
- return;
- }
- void UsernamePasswordGenerator::on_pushButton_9_clicked()
- {
- QString username = ui->lineEdit_3->text();
- QString password = ui->lineEdit_2->text();
- QString savePath = QFileDialog::getSaveFileName(this, tr("Save File"), "/home/Desktop/untitled.txt", tr("Textfile (*.txt)"));
- username = "Username: " + username + "\n";
- password = "Password: " + password + "\n";
- FILE *saveFile;
- saveFile = fopen(savePath.toStdString().c_str(), "w");
- fwrite(username.toStdString().c_str(), sizeof(char), username.length(), saveFile);
- fwrite(password.toStdString().c_str(), sizeof(char), password.length(), saveFile);
- fclose(saveFile);
- return;
- }
- void UsernamePasswordGenerator::on_pushButton_11_clicked()
- {
- if(ui->pushButton_11->text() == "Hide")
- {
- ui->pushButton_11->setText("View");
- ui->lineEdit_3->setEchoMode(QLineEdit::Password);
- }
- else if (ui->pushButton_11->text() == "View")
- {
- ui->pushButton_11->setText("Hide");
- ui->lineEdit_3->setEchoMode(QLineEdit::Normal);
- }
- return;
- }
- void UsernamePasswordGenerator::on_pushButton_7_clicked()
- {
- if(ui->pushButton_7->text() == "Hide")
- {
- ui->pushButton_7->setText("View");
- ui->lineEdit_2->setEchoMode(QLineEdit::Password);
- }
- else if (ui->pushButton_7->text() == "View")
- {
- ui->pushButton_7->setText("Hide");
- ui->lineEdit_2->setEchoMode(QLineEdit::Normal);
- }
- return;
- }
- void UsernamePasswordGenerator::on_pushButton_8_clicked()
- {
- //re generate the username and password and set the text in lineedit 3 and 2 to the
- //generated numbers
- //do this by reading all the variables that changes the outcome of the username and password
- //and depening on them, generate the password and username.
- /*
- bool lowercase = false;
- bool uppercase = false;
- bool decimalNumbers = false;
- bool nonAlphaNumerical = false;
- bool ascii32To255 = false;
- */
- //do some character checking here and determine the allowed characters.
- int min1, max1;
- int min2, max2;
- int min3, max3;
- int min4, max4;
- if(ascii32To255)
- {
- //range = 32 - 255
- min1 = 32;
- max1 = 255;
- min2 = min3 = min4 = -1;
- max2 = max3 = max4 = -1;
- qDebug() << "0";
- }
- else
- {
- if(lowercase & uppercase & decimalNumbers & nonAlphaNumerical)
- {
- //define range for all
- //range = 32 - 126
- min1 = 32;
- max1 = 126;
- min2 = min3 = min4 = -1;
- max2 = max3 = max4 = -1;
- qDebug() << "1";
- }
- else if(lowercase & uppercase & decimalNumbers & !nonAlphaNumerical)
- {
- //define range for all but non alpha
- //range = 48 - 57, 65 - 90, 97 - 122
- min1 = 48;
- max1 = 57;
- min2 = 65;
- max2 = 90;
- min3 = 97;
- max3 = 122;
- min4 = -1;
- max4 = -1;
- qDebug() << "2";
- }
- else if(!lowercase & uppercase & decimalNumbers & nonAlphaNumerical)
- {
- //define range for all but lowercase
- //range = 48 - 57, 65 - 90, 32 - 126
- min1 = 48;
- max1 = 57;
- min2 = 65;
- max2 = 90;
- min3 = 32;
- max3 = 126;
- min4 = -1;
- max4 = -1;
- qDebug() << "3";
- }
- else if(lowercase & !uppercase & decimalNumbers & nonAlphaNumerical)
- {
- //define range for all but uppercase
- //range = 48 - 57, 97 - 122, 32 - 126
- min1 = 48;
- max1 = 57;
- min2 = 97;
- max2 = 122;
- min3 = 32;
- max3 = 126;
- min4 = -1;
- max4 = -1;
- qDebug() << "4";
- }
- else if(lowercase & uppercase & !decimalNumbers & nonAlphaNumerical)
- {
- //define range for all but decimalNumbers
- //range = 65 - 90, 97 - 122, 32 - 126
- min1 = 65;
- max1 = 90;
- min2 = 97;
- max2 = 122;
- min3 = 32;
- max3 = 126;
- min4 = -1;
- max4 = -1;
- qDebug() << "5";
- }
- else if(!lowercase & !uppercase & !decimalNumbers & nonAlphaNumerical)
- {
- //define range for only non alpha
- //range = 32 - 47, 58 - 64, 91 - 96, 123 - 126
- min1 = 32;
- max1 = 47;
- min2 = 58;
- max2 = 64;
- min3 = 91;
- max3 = 96;
- min4 = 123;
- max4 = 126;
- qDebug() << "6";
- }
- else if(lowercase & !uppercase & !decimalNumbers & !nonAlphaNumerical)
- {
- //define range for only lower
- //range = 97 - 122
- min1 = 97;
- max1 = 122;
- min2 = min3 = min4 = -1;
- max2 = max3 = max4 = -1;
- qDebug() << "7";
- }
- else if(!lowercase & uppercase & !decimalNumbers & !nonAlphaNumerical)
- {
- //define range for only uppercase
- //range = 65 - 90
- min1 = 65;
- max1 = 90;
- min2 = min3 = min4 = -1;
- max2 = max3 = max4 = -1;
- qDebug() << "8";
- }
- else if(!lowercase & !uppercase & decimalNumbers & !nonAlphaNumerical)
- {
- //define range for only decimal numbers
- //range = 48 - 57
- min1 = 48;
- max1 = 57;
- min2 = min3 = min4 = -1;
- max2 = max3 = max4 = -1;
- qDebug() << "9";
- }
- else if(lowercase & !uppercase & !decimalNumbers & nonAlphaNumerical)
- {
- //define range for non alpha and lower
- //range = 32 - 47, 58 - 64, 91 - 126
- min1 = 32;
- max1 = 47;
- min2 = 58;
- max2 = 64;
- min3 = 91;
- max3 = 126;
- min4 = -1;
- max4 = -1;
- qDebug() << "10";
- }
- else if(!lowercase & uppercase & !decimalNumbers & nonAlphaNumerical)
- {
- //define range for non alpha and uppercase
- //range = 32 - 47, 58 - 126
- min1 = 32;
- max1 = 47;
- min2 = 58;
- max2 = 126;
- min3 = min4 = -1;
- max3 = max4 = -1;
- qDebug() << "11";
- }
- else if(!lowercase & !uppercase & decimalNumbers & nonAlphaNumerical)
- {
- //define range for non alpha and decimal
- //range = 32 - 64, 92 - 96, 123 - 126
- min1 = 32;
- max1 = 64;
- min2 = 92;
- max2 = 96;
- min3 = 123;
- max3 = 126;
- min4 = -1;
- max4 = -1;
- qDebug() << "12";
- }
- else if(lowercase & uppercase & !decimalNumbers & !nonAlphaNumerical)
- {
- //define range for lower and uppercase
- //range = 65 - 90, 97 - 122
- min1 = 65;
- max1 = 90;
- min2 = 97;
- max2 = 122;
- min3 = min4 = -1;
- max3 = max4 = -1;
- qDebug() << "13";
- }
- else if(lowercase & !uppercase & decimalNumbers & !nonAlphaNumerical)
- {
- //define range for lower and decimal numbers
- //range = 48 - 57, 97 - 122
- min1 = 48;
- max1 = 57;
- min2 = 97;
- max2 = 122;
- min3 = min4 = -1;
- max3 = max4 = -1;
- qDebug() << "14";
- }
- else if(!lowercase & uppercase & decimalNumbers & !nonAlphaNumerical)
- {
- //define range fo ruppercase and decimal numbers
- //range = 65 - 90, 48 - 57
- min1 = 65;
- max1 = 90;
- min2 = 48;
- max2 = 57;
- min3 = min4 = -1;
- max3 = max4 = -1;
- qDebug() << "15";
- }
- else if(!lowercase & !uppercase & !decimalNumbers & !nonAlphaNumerical)
- {
- //define range for nothing
- min1 = min2 = min3 = min4 = -1;
- max1 = max2 = max3 = max4 = -1;
- qDebug() << "16";
- }
- }
- if(((min1 == -1) & (min2 == -1) & (min3 == -1) & (min4 == -1)) || ((max1 == -1) & (max2 == -1) & (max3 == -1) & (max4 == -1)))
- {
- QMessageBox messageBox;
- messageBox.information(0,"Notification","None of the check boxes are filled! Retard...");
- messageBox.setFixedSize(500,200);
- }
- else
- {
- setRandomSeed();
- QString newUsername = "";
- QString newPassword = "";
- for(int i = 0; i < ui->horizontalSlider_2->value(); i++)
- {
- newUsername += (char)pullRandomNumber(min1, max1, min2, max2, min3, max3, min4, max4);
- }
- for(int i = 0; i < ui->horizontalSlider_2->value(); i++)
- {
- newPassword += (char)pullRandomNumber(min1, max1, min2, max2, min3, max3, min4, max4);
- }
- ui->lineEdit_3->setText(newUsername);
- ui->lineEdit_2->setText(newPassword);
- }
- return;
- }
- void UsernamePasswordGenerator::on_horizontalSlider_2_valueChanged(int value)
- {
- ui->spinBox_5->setValue(value);
- return;
- }
- void UsernamePasswordGenerator::on_spinBox_5_valueChanged(int arg1)
- {
- ui->horizontalSlider_2->setValue(arg1);
- return;
- }
- void UsernamePasswordGenerator::on_spinBox_4_valueChanged(int arg1)
- {
- if(arg1 < ui->spinBox_6->value())
- {
- ui->spinBox_4->setValue(ui->spinBox_6->value());
- }
- ui->horizontalSlider_2->setMaximum(arg1);
- ui->spinBox_5->setMaximum(arg1);
- return;
- }
- void UsernamePasswordGenerator::on_spinBox_6_valueChanged(int arg1)
- {
- if(arg1 > ui->spinBox_4->value())
- {
- ui->spinBox_4->setValue(ui->spinBox_6->value());
- }
- ui->horizontalSlider_2->setMinimum(arg1);
- ui->spinBox_5->setMinimum(arg1);
- return;
- }
- void UsernamePasswordGenerator::on_checkBox_6_stateChanged(int arg1)
- {
- if(arg1)
- {
- uppercase = true;
- }
- else
- {
- uppercase = false;
- }
- return;
- }
- void UsernamePasswordGenerator::on_checkBox_10_stateChanged(int arg1)
- {
- if(arg1)
- {
- lowercase = true;
- }
- else
- {
- lowercase = false;
- }
- return;
- }
- void UsernamePasswordGenerator::on_checkBox_7_stateChanged(int arg1)
- {
- if(arg1)
- {
- decimalNumbers = true;
- }
- else
- {
- decimalNumbers = false;
- }
- return;
- }
- void UsernamePasswordGenerator::on_checkBox_9_stateChanged(int arg1)
- {
- if(arg1)
- {
- nonAlphaNumerical = true;
- }
- else
- {
- nonAlphaNumerical = false;
- }
- return;
- }
- void UsernamePasswordGenerator::on_checkBox_8_stateChanged(int arg1)
- {
- if(arg1)
- {
- ascii32To255 = true;
- }
- else
- {
- ascii32To255 = false;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement