暫無描述

mainwindow.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QDebug>
  4. #include <QLineEdit>
  5. /// \file
  6. /// \fn MainWindow::MainWindow(QWidget *parent)
  7. /// \~English
  8. /// \brief Constructor
  9. /// \~Spanish
  10. /// \brief Constructor
  11. MainWindow::MainWindow(QWidget *parent) :
  12. QMainWindow(parent),
  13. ui(new Ui::MainWindow)
  14. {
  15. ui->setupUi(this);
  16. }
  17. /// \fn MainWindow::~MainWindow()
  18. /// \~English
  19. /// \brief Destructor
  20. /// \~Spanish
  21. /// \brief Destructor
  22. MainWindow::~MainWindow()
  23. {
  24. delete ui;
  25. }
  26. /// \fn void MainWindow::on_lineEdit_textChanged(const QString &arg1)
  27. /// \~English
  28. /// \brief Function that is called every time the password text box field is
  29. /// changed.
  30. /// \param arg1 string with the current value of the password text box
  31. /// \~Spanish
  32. /// \brief Funcion que es llamada cada ves que la caja de texto para la contrasena
  33. /// es cambiada.
  34. /// \param arg1 cadena con el valor corriente de la caja de texto para la contrasena.
  35. void MainWindow::on_lineEdit_textChanged(const QString &arg1)
  36. {
  37. setNumberOfCharacters(0,0);
  38. setUpperCharacters(0,0);
  39. setLowerCharacters(0,0);
  40. setDigits(0,0);
  41. setDigitsOnly(0,0);
  42. setSymbols(0,0);
  43. setConsecutiveDigits(0,0);
  44. setConsecutiveLower(0,0);
  45. setConsecutiveUpper(0,0);
  46. setMiddleDigitsOrSymbols(0,0);
  47. setRequirements(0,0);
  48. setLettersOnly(0,0);
  49. // The function the student needs to work with
  50. // La funcion en la que el estudiante va a trabajar.
  51. readPass(arg1.toStdString());
  52. }
  53. /// \fn void MainWindow::on_HiddenCheckBox_clicked(bool checked)
  54. /// \~English
  55. /// \brief Function that is called when the password hidden checkbox is selected.
  56. /// \param checked boolean value
  57. /// \~Spanish
  58. /// \brief Funcion que es llamada cuando la caja de seleccion (checkbox) de esconder
  59. /// el password es seleccionada.
  60. void MainWindow::on_HiddenCheckBox_clicked(bool checked)
  61. {
  62. if (checked) ui->lineEdit->setEchoMode(QLineEdit::Password);
  63. else ui->lineEdit->setEchoMode(QLineEdit::Normal);
  64. }
  65. /// \fn void MainWindow::setNumberOfCharacters(int count, int score)
  66. /// \~English
  67. /// \brief Function to set the number of characters and score in the GUI
  68. /// \param count the number of characters found.
  69. /// \param score the score given by the count of characters found.
  70. /// \~Spanish
  71. /// \brief Funcion para establecer el number de caracteres y la puntuacion en el GUI
  72. /// \param count el numero de letras encontrado.
  73. /// \param score le puntuacion dada por la cuenta de las letras.
  74. void MainWindow::setNumberOfCharacters(int count, int score){
  75. ui->NumberOfCharCount->setText(QString::number(count));
  76. ui->NumberOfCharScore->setText(QString::number(score));
  77. ui->NumberCharCheckBox->setChecked(count > 0);
  78. }
  79. /// \fn void MainWindow::setUpperCharacters(int count, int score)
  80. /// \~English
  81. /// \brief Function to set the number of upper case characters and score in the GUI
  82. /// \param count the number of upper case characters found.
  83. /// \param score the score given by the count of upper case characters.
  84. /// \~Spanish
  85. /// \brief Funcion para establecer el number de caracteres mayusculas y la puntuacion en el GUI
  86. /// \param count el numero de letras mayusculas encontrado.
  87. /// \param score le puntuacion dada por la cuenta de letras mayusculas encontrada.
  88. void MainWindow::setUpperCharacters(int count, int score){
  89. ui->UppercaseCountLabel->setText(QString::number(count));
  90. ui->UppercaseScoreLabel->setText(QString::number(score));
  91. ui->UppercaseCheckBox->setChecked(count > 0);
  92. }
  93. /// \fn void MainWindow::setLowerCharacters(int count, int score)
  94. /// \~English
  95. /// \brief Function to set the number of lower case characters and score in the GUI
  96. /// \param count the number of lower case characters found.
  97. /// \param score the score given by the count of lower case characters.
  98. /// \~Spanish
  99. /// \brief Funcion para establecer el number de caracteres minusculas y la puntuacion en el GUI
  100. /// \param count el numero de letras minusculas encontrado.
  101. /// \param score le puntuacion dada por la cuenta de letras minusculas encontrada.
  102. void MainWindow::setLowerCharacters(int count, int score){
  103. ui->LowerCaseCountLabel->setText(QString::number(count));
  104. ui->LowerCaseScoreLabel->setText(QString::number(score));
  105. ui->LowercaseCheckBox->setChecked(count > 0);
  106. }
  107. /// \fn void MainWindow::setDigits(int count, int score)
  108. /// \~English
  109. /// \brief Function to set the number of digits characters and score in the GUI
  110. /// \param count the number of digits found.
  111. /// \param score the score given by the count of digit characters.
  112. /// \~Spanish
  113. /// \brief Funcion para establecer el number de digitos y la puntuacion en el GUI
  114. /// \param count el numero de digitos encontrado.
  115. /// \param score le puntuacion dada por la cuenta de digitos encontrada.
  116. void MainWindow::setDigits(int count, int score){
  117. ui->NumbersCountlabel->setText(QString::number(count));
  118. ui->NumberScorelabel->setText(QString::number(score));
  119. ui->NumbersCheckBox->setChecked(count > 0);
  120. }
  121. /// \fn void MainWindow::setSymbols(int count, int score)
  122. /// \~English
  123. /// \brief Function to set the number of symbols characters and score in the GUI
  124. /// \param count the number of symbols found.
  125. /// \param score the score given by the count of symbols.
  126. /// \~Spanish
  127. /// \brief Funcion para establecer el number de simbolos y la puntuacion en el GUI
  128. /// \param count el numero de simbolos encontrado.
  129. /// \param score le puntuacion dada por la cuenta de simbolos encontrada.
  130. void MainWindow::setSymbols(int count, int score){
  131. ui->SymbolsCountlabel->setText(QString::number(count));
  132. ui->SymbolScorelabel->setText(QString::number(score));
  133. ui->SymbolsCheckBox->setChecked(count > 0);
  134. }
  135. /// \fn void MainWindow::setMiddleDigitsOrSymbols(int count, int score)
  136. /// \~English
  137. /// \brief Function to set the number of middle digits or symbols and score in the GUI
  138. /// \param count the number of middle digits or symbols found.
  139. /// \param score the score given by the count of middle digits or symbols.
  140. /// \~Spanish
  141. /// \brief Funcion para establecer el number de simbolos o digitos entre medio y la puntuacion en el GUI
  142. /// \param count el numero de simbolos y digitos entre medio encontrado.
  143. /// \param score le puntuacion dada por la cuenta de simbolos y digitos entre medio encontrada.
  144. void MainWindow::setMiddleDigitsOrSymbols(int count, int score){
  145. ui->MidNumOrSymCountlabel->setText(QString::number(count));
  146. ui->MidNumOrSymScorelabel->setText(QString::number(score));
  147. ui->MiddleCheckBox->setChecked(count > 0);
  148. }
  149. /// \fn void MainWindow::setRequirements(int count, int score)
  150. /// \~English
  151. /// \brief Function to set the number password strength requirements met and score in the GUI
  152. /// \param count the number of requirements met.
  153. /// \param score the score given by requirements.
  154. /// \~Spanish
  155. /// \brief Funcion para establecer el number de requisitos cumplidos para password fuertes
  156. /// y la puntuacion en el GUI
  157. /// \param count el numero de requisitos .
  158. /// \param score le puntuacion dada por la cuenta requisitos.
  159. void MainWindow::setRequirements(int count, int score){
  160. ui->ReqCountlabel->setText(QString::number(count));
  161. ui->ReqScorelabel->setText(QString::number(score));
  162. ui->RequirementCheckBox->setChecked(count > 0);
  163. }
  164. /// \fn void MainWindow::setLettersOnly(int count, int score)
  165. /// \~English
  166. /// \brief Function to set the number of letters if there were only letters and score in the GUI
  167. /// \param count the number of letters only found.
  168. /// \param score the score given by letters only found.
  169. /// \~Spanish
  170. /// \brief Funcion para establecer el number de letras si solo habían letras
  171. /// y la puntuacion en el GUI
  172. /// \param count el numero de letras solamente encontradas .
  173. /// \param score le puntuacion dada por la cuenta solamente de letras encontradas.
  174. void MainWindow::setLettersOnly(int count, int score){
  175. ui->LettersOnlyCountLabel->setText(QString::number(count));
  176. ui->LettersOnlyScoreLabel->setText(QString::number(score));
  177. ui->LettersOnlyCheckBox->setChecked(count > 0);
  178. }
  179. /// \fn void MainWindow::setDigitsOnly(int count, int score)
  180. /// \~English
  181. /// \brief Function to set the number of digits if there were only digits and score in the GUI
  182. /// \param count the number of digits only found.
  183. /// \param score the score given by digits only found.
  184. /// \~Spanish
  185. /// \brief Funcion para establecer el number de digitos si solo habían digitos
  186. /// y la puntuacion en el GUI
  187. /// \param count el numero de digitos solamente encontradas .
  188. /// \param score le puntuacion dada por la cuenta solamente de digitos encontradas.
  189. void MainWindow::setDigitsOnly(int count, int score){
  190. ui->NumOnlyCountLabel->setText(QString::number(count));
  191. ui->NumOnlyScoreLabel->setText(QString::number(score));
  192. ui->NumbersOnlyCheckBox->setChecked(count > 0);
  193. }
  194. /// \fn void MainWindow::setConsecutiveUpper(int count, int score)
  195. /// \~English
  196. /// \brief Function to set the number of consecutive upper characters and score in the GUI
  197. /// \param count the number of consecutive upper characters found.
  198. /// \param score the score given by the count of consecutive upper characters found.
  199. /// \~Spanish
  200. /// \brief Funcion para establecer el number de letras mayusculas consecutivas y la puntuacion en el GUI
  201. /// \param count el numero de letras mayusculas consecutivas encontrado.
  202. /// \param score le puntuacion dada por la cuenta de las letras mayusculas consecutivas.
  203. void MainWindow::setConsecutiveUpper(int count, int score){
  204. ui->ConsUpperCountLabel->setText(QString::number(count));
  205. ui->ConsUpperScoreLabel->setText(QString::number(score));
  206. ui->ConsecutiveUpperCheckBox->setChecked(count > 0);
  207. }
  208. /// \fn void MainWindow::setConsecutiveLower(int count, int score)
  209. /// \~English
  210. /// \brief Function to set the number of consecutive lower characters and score in the GUI
  211. /// \param count the number of consecutive lower characters found.
  212. /// \param score the score given by the count of consecutive lower characters found.
  213. /// \~Spanish
  214. /// \brief Funcion para establecer el number de letras minusculas consecutivas y la puntuacion en el GUI
  215. /// \param count el numero de letras minusculas consecutivas encontrado.
  216. /// \param score le puntuacion dada por la cuenta de las letras minusculas consecutivas.
  217. void MainWindow::setConsecutiveLower(int count, int score){
  218. ui->ConsLowerCountLabel->setText(QString::number(count));
  219. ui->ConsLowerScoreLabel->setText(QString::number(score));
  220. ui->ConsecutiveLowerCheckBox->setChecked(count > 0);
  221. }
  222. /// \fn void MainWindow::setConsecutiveDigits(int count, int score)
  223. /// \~English
  224. /// \brief Function to set the number of consecutive digits and score in the GUI
  225. /// \param count the number of consecutive digits found.
  226. /// \param score the score given by the count of consecutive digits found.
  227. /// \~Spanish
  228. /// \brief Funcion para establecer el number de digitos consecutivos y la puntuacion en el GUI
  229. /// \param count el numero de digitos consecutivos encontrado.
  230. /// \param score le puntuacion dada por la cuenta de los digitos consecutivos.
  231. void MainWindow::setConsecutiveDigits(int count, int score){
  232. ui->ConsNumsCountLabel->setText(QString::number(count));
  233. ui->ConsNumsScoreLabel->setText(QString::number(score));
  234. ui->ConsecutiveNumbersCheckBox->setChecked(count > 0);
  235. }
  236. /// \fn void MainWindow::strengthDisplay(string strength, int totalScore)
  237. /// \~English
  238. /// \brief Function to set the computed strength and total score password
  239. /// strength in the GUI.
  240. /// \param strength Computed strenght of the password.
  241. /// \param totalScore Total score of the strength of the password.
  242. /// \~Spanish
  243. /// \brief Funcion para establecer la fuerza y la puntuacion total calculada de la contrasena.
  244. /// \param strength Fuerza computada de la contrasena.
  245. /// \param totalScore Puntuacion total de la fuerza de la contrasena.
  246. void MainWindow::strengthDisplay(string strength, int totalScore){
  247. if(totalScore > 100){
  248. totalScore = 100;
  249. QString percent = QString::number(totalScore) + "%";
  250. ui->progressBar->setValue(totalScore);
  251. ui->progressLabel->setText(percent);
  252. }
  253. else if(totalScore < 0){
  254. totalScore = 0;
  255. QString percent = QString::number(totalScore) + "%";
  256. ui->progressBar->setValue(totalScore);
  257. ui->progressLabel->setText(percent);
  258. }
  259. else{
  260. QString percent = QString::number(totalScore) + "%";
  261. ui->progressBar->setValue(totalScore);
  262. ui->progressLabel->setText(percent);
  263. }
  264. ui->statusLabel->setText(QString::fromStdString(strength));
  265. }