* @brief Prompts for the password, verifies it, and clears the lock on success. */
| 679 | * @brief Prompts for the password, verifies it, and clears the lock on success. |
| 680 | */ |
| 681 | void DataModel::ProjectModel::unlockProject() |
| 682 | { |
| 683 | if (m_passwordHash.isEmpty()) { |
| 684 | if (m_locked) { |
| 685 | m_locked = false; |
| 686 | Q_EMIT lockedChanged(); |
| 687 | } |
| 688 | return; |
| 689 | } |
| 690 | |
| 691 | bool ok = false; |
| 692 | const auto pwd = QInputDialog::getText(nullptr, |
| 693 | tr("Unlock Project"), |
| 694 | tr("Enter the project password:"), |
| 695 | QLineEdit::Password, |
| 696 | QString(), |
| 697 | &ok); |
| 698 | if (!ok) |
| 699 | return; |
| 700 | |
| 701 | if (!Misc::PasswordHash::verifyPassword(pwd, m_passwordHash)) { |
| 702 | QTimer::singleShot(0, this, [] { |
| 703 | Misc::Utilities::showMessageBox( |
| 704 | tr("Incorrect password"), |
| 705 | tr("The password you entered does not match the one stored in the project file."), |
| 706 | QMessageBox::Warning); |
| 707 | }); |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | m_passwordHash.clear(); |
| 712 | |
| 713 | if (m_locked) { |
| 714 | m_locked = false; |
| 715 | Q_EMIT lockedChanged(); |
| 716 | } |
| 717 | |
| 718 | if (validateProject(true)) { |
| 719 | setModified(true); |
| 720 | (void)saveJsonFile(false); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | //-------------------------------------------------------------------------------------------------- |
| 725 | // Document information |