Хэширование пароля

This commit is contained in:
2025-10-16 17:11:58 +03:00
parent 8e931f229b
commit 241382d305
19 changed files with 221 additions and 116 deletions

View File

@@ -11,6 +11,8 @@ DialogAuthorizationInstructor::DialogAuthorizationInstructor(QWidget *parent) :
ui->editLogin->setProperty("mandatoryField", true);
ui->editPassword->setProperty("mandatoryField", true);
ui->btnViewPassword->setObjectName("btnViewPassword");
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
ui->editLogin->setValidator(new QRegExpValidator(QRegExp("[A-Za-z\\d]+"), this));
@@ -30,3 +32,13 @@ void DialogAuthorizationInstructor::on_btnLogIn_clicked()
{
this->accept();
}
void DialogAuthorizationInstructor::on_btnViewPassword_pressed()
{
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Normal);
}
void DialogAuthorizationInstructor::on_btnViewPassword_released()
{
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
}

View File

@@ -30,6 +30,10 @@ public:
private slots:
void on_btnLogIn_clicked();
void on_btnViewPassword_pressed();
void on_btnViewPassword_released();
private:
Ui::DialogAuthorizationInstructor *ui;
};

View File

@@ -71,16 +71,31 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="editPassword">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_Password">
<item>
<widget class="QLineEdit" name="editPassword">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnViewPassword">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/resources/icons/eye.png</normaloff>:/resources/icons/eye.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>

View File

@@ -15,8 +15,17 @@ DialogEditInstructor::DialogEditInstructor(QWidget *parent) :
ui->editLogin->setProperty("mandatoryField", true);
ui->editPassword->setProperty("mandatoryField", true);
ui->btnViewPassword->setObjectName("btnViewPassword");
ui->editLogin->setValidator(new QRegExpValidator(QRegExp("[A-Za-z\\d]+"), this));
ui->editPassword->setEnabled(false);
//#ifndef PROJECT_TYPE_DEBUG
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
//#endif
ui->btnViewPassword->setEnabled(false);
ui->btnOK->setEnabled(false);
}
@@ -42,6 +51,14 @@ void DialogEditInstructor::setInstructor(Instructor instructor)
else
ui->editName->setEnabled(true);
if(instructor.getNeedSetPassword())
{
ui->editPassword->setEnabled(true);
ui->btnViewPassword->setEnabled(true);
}
//else
//ui->editPassword->setText("*****");
ui->btnOK->setEnabled(false);
}
@@ -89,3 +106,13 @@ void DialogEditInstructor::on_btnOK_clicked()
{
this->accept();
}
void DialogEditInstructor::on_btnViewPassword_pressed()
{
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Normal);
}
void DialogEditInstructor::on_btnViewPassword_released()
{
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
}

View File

@@ -29,6 +29,10 @@ private slots:
void on_btnOK_clicked();
void on_btnViewPassword_pressed();
void on_btnViewPassword_released();
private:
void verify();

View File

@@ -77,7 +77,28 @@
<widget class="QLineEdit" name="editLogin"/>
</item>
<item>
<widget class="QLineEdit" name="editPassword"/>
<layout class="QHBoxLayout" name="horizontalLayout_Password">
<item>
<widget class="QLineEdit" name="editPassword"/>
</item>
<item>
<widget class="QToolButton" name="btnViewPassword">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/resources/icons/eye.png</normaloff>:/resources/icons/eye.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>

View File

@@ -47,59 +47,17 @@ void EditorInstructors::on_btnNewInstructor_clicked()
Instructor instructor;
Instructor instructor_edit;
instructor.setNeedSetPassword(true);
if(editInstructor(instructor, &instructor_edit))
{
waitAnimationWidget->showWithPlay();
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR, 0, &instructor_edit);
}
lastCurrentID = 0;
return;
/*
if(int id_instructor = dbLMS->newInstructor())
{
loadInstructorsFromDB();
setCurrentInstructor(id_instructor);
DialogEditInstructor dlg(this);
Instructor instructor = dbLMS->getInstructor(id_instructor);
if(instructor.getID() == 0)
return;
dlg.setInstructor(instructor);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
Instructor instructor_edit = dlg.getInstructor();
if(int id_edit = dbLMS->editInstructor(instructor_edit))
{//Отредактировано
loadInstructorsFromDB();
setCurrentInstructor(id_edit);
return;
}
else
{
dlg.setInstructor(instructor_edit);
continue;
}
}
case QDialog::Rejected:
dbLMS->delInstructor(id_instructor);
loadInstructorsFromDB();
return;
default:
dbLMS->delInstructor(id_instructor);
loadInstructorsFromDB();
return;
}
}
}
*/
}
void EditorInstructors::on_btnDeleteInstructor_clicked()
@@ -353,6 +311,13 @@ bool EditorInstructors::editInstructor(Instructor instructor, Instructor* instru
continue;
}
if(instructor_edit->getNeedSetPassword())
{
//Хэшируем пароль
instructor_edit->hashingPassword();
instructor_edit->setNeedSetPassword(false);
}
return true;
}
case QDialog::Rejected:

View File

@@ -5,6 +5,7 @@
#include "dialogauthorizationinstructor.h"
#include "dialogsettings.h"
#include "specialmessagebox.h"
#include "hashtools.h"
const QString InstructorsAndTraineesWidget::languageENG = "en_EN";
@@ -314,6 +315,9 @@ bool InstructorsAndTraineesWidget::authorizationInstructorDialog(QWidget* parent
QString login = dlg.getLogin();
QString password = dlg.getPassword();
// Вычисление MD5 хэша
password = HashTools::hashingMD5string(password);
connectorToServer->authorizationInstructorLocal(login, password);
return true;

View File

@@ -53,5 +53,6 @@
<file>resources/icons/warning.png</file>
<file>resources/icons/info.png</file>
<file>resources/icons/personalCard.png</file>
<file>resources/icons/eye.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@@ -15,7 +15,18 @@ DialogEditTrainee::DialogEditTrainee(QWidget *parent) :
ui->editLogin->setProperty("mandatoryField", true);
ui->editPassword->setProperty("mandatoryField", true);
ui->btnViewPassword->setObjectName("btnViewPassword");
ui->editLogin->setValidator(new QRegExpValidator(QRegExp("[A-Za-z\\d]+"), this));
ui->editPassword->setEnabled(false);
//#ifndef PROJECT_TYPE_DEBUG
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
//#endif
ui->btnViewPassword->setEnabled(false);
ui->btnOK->setEnabled(false);
}
DialogEditTrainee::~DialogEditTrainee()
@@ -34,6 +45,14 @@ void DialogEditTrainee::setTrainee(Trainee trainee)
ui->checkArchived->setChecked(trainee.getArchived());
ui->checkLoggedIn->setChecked(trainee.getLoggedIn());
if(trainee.getNeedSetPassword())
{
ui->editPassword->setEnabled(true);
ui->btnViewPassword->setEnabled(true);
}
//else
//ui->editPassword->setText("*****");
ui->btnOK->setEnabled(false);
}
@@ -80,3 +99,13 @@ void DialogEditTrainee::on_btnOK_clicked()
{
this->accept();
}
void DialogEditTrainee::on_btnViewPassword_pressed()
{
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Normal);
}
void DialogEditTrainee::on_btnViewPassword_released()
{
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
}

View File

@@ -28,6 +28,10 @@ private slots:
void on_btnOK_clicked();
void on_btnViewPassword_pressed();
void on_btnViewPassword_released();
private:
void verify();

View File

@@ -85,13 +85,28 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="editPassword">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_Password">
<item>
<widget class="QLineEdit" name="editPassword">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnViewPassword">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/resources/icons/eye.png</normaloff>:/resources/icons/eye.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>

View File

@@ -148,63 +148,14 @@ void EditorTrainees::on_btnNewTrainee_clicked()
Trainee trainee;
Trainee trainee_edit;
trainee.setNeedSetPassword(true);
if(editTrainee(trainee, &trainee_edit))
{
waitAnimationWidget->showWithPlay();
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_NEW_TRAINEE, id_group, &trainee_edit);
}
return;
/*
if(int id_trainee = dbLMS->newTrainee(id_group))
{
loadTraineesFromDB();
setCurrentGroup(id_group);
DialogEditTrainee dlg(this);
Trainee trainee = dbLMS->getTrainee(id_trainee);
if(trainee.getID() == 0)
return;
dlg.setTrainee(trainee);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
Trainee trainee_edit = dlg.getTrainee();
if(int id_edit = dbLMS->editTrainee(trainee_edit))
{//Отредактировано
loadTraineesFromDB();
//setCurrentTrainee(id_edit);
setCurrentGroup(id_group);
return;
}
else
{
dlg.setTrainee(trainee_edit);
continue;
}
break;
}
case QDialog::Rejected:
dbLMS->delTrainee(id_trainee);
loadTraineesFromDB();
setCurrentGroup(id_group);
return;
default:
dbLMS->delTrainee(id_trainee);
loadTraineesFromDB();
setCurrentGroup(id_group);
return;
}
}
}*/
}
}
}
@@ -582,6 +533,13 @@ bool EditorTrainees::editTrainee(Trainee trainee, Trainee *trainee_edit)
continue;
}
if(trainee_edit->getNeedSetPassword())
{
//Хэшируем пароль
trainee_edit->hashingPassword();
trainee_edit->setNeedSetPassword(false);
}
return true;
}
case QDialog::Rejected: