diff options
| author | moneromooo.monero <moneromooo.monero@users.noreply.github.com> | 2016-12-16 00:11:37 +0000 |
|---|---|---|
| committer | moneromooo.monero <moneromooo.monero@users.noreply.github.com> | 2016-12-17 11:32:33 +0000 |
| commit | fbe19d23b70cb051e6089128c7eec1b82589f680 (patch) | |
| tree | 43f4439d09a37c7055a9b4cf1612d6be4449b08b | |
| parent | b882de8e1ccfd3965eddbfb90e75b7d6d229f32c (diff) | |
| download | monzero-gui-fbe19d23b70cb051e6089128c7eec1b82589f680.tar.gz monzero-gui-fbe19d23b70cb051e6089128c7eec1b82589f680.tar.xz monzero-gui-fbe19d23b70cb051e6089128c7eec1b82589f680.zip | |
Use zxcvbn for password strength estimation
| -rw-r--r-- | src/libwalletqt/WalletManager.cpp | 16 | ||||
| -rw-r--r-- | src/libwalletqt/WalletManager.h | 2 | ||||
| -rw-r--r-- | wizard/WizardPassword.qml | 3 | ||||
| -rw-r--r-- | wizard/utils.js | 32 |
4 files changed, 20 insertions, 33 deletions
diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 0ff8d74d..64e9a1db 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -1,6 +1,7 @@ #include "WalletManager.h" #include "Wallet.h" #include "wallet/wallet2_api.h" +#include "zxcvbn-c/zxcvbn.h" #include <QFile> #include <QFileInfo> #include <QDir> @@ -241,6 +242,21 @@ QUrl WalletManager::localPathToUrl(const QString &path) const return QUrl::fromLocalFile(path); } +double WalletManager::getPasswordStrength(const QString &password) const +{ + static const char *local_dict[] = { + "monero", "fluffypony", NULL + }; + + if (!ZxcvbnInit("zxcvbn.dict")) { + fprintf(stderr, "Failed to open zxcvbn.dict\n"); + return 0.0; + } + double e = ZxcvbnMatch(password.toStdString().c_str(), local_dict, NULL); + ZxcvbnUnInit(); + return e; +} + WalletManager::WalletManager(QObject *parent) : QObject(parent) { m_pimpl = Monero::WalletManagerFactory::getWalletManager(); diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 88425f6f..fb3dd142 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -114,6 +114,8 @@ public: Q_INVOKABLE qint64 addi(qint64 x, qint64 y) const { return x + y; } Q_INVOKABLE qint64 subi(qint64 x, qint64 y) const { return x - y; } + Q_INVOKABLE double getPasswordStrength(const QString &password) const; + signals: void walletOpened(Wallet * wallet); diff --git a/wizard/WizardPassword.qml b/wizard/WizardPassword.qml index 3c66f83c..1e5013cf 100644 --- a/wizard/WizardPassword.qml +++ b/wizard/WizardPassword.qml @@ -26,6 +26,7 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import moneroComponents.WalletManager 1.0 import QtQuick 2.2 import "../components" import "utils.js" as Utils @@ -76,7 +77,7 @@ Item { wizard.nextButton.enabled = passwordItem.password === retypePasswordItem.password // scorePassword returns value from 1..100 - var strength = Utils.scorePassword(passwordItem.password) + var strength = walletManager.getPasswordStrength(passwordItem.password); // privacyLevel component uses 1..13 scale privacyLevel.fillLevel = Utils.mapScope(1, 100, 1, 13, strength) diff --git a/wizard/utils.js b/wizard/utils.js index be066598..7b9fc241 100644 --- a/wizard/utils.js +++ b/wizard/utils.js @@ -1,37 +1,5 @@ - .pragma library -// grabbed from SO answer page: http://stackoverflow.com/questions/948172/password-strength-meter - -function scorePassword(pass) { - var score = 0; - if (!pass) - return score; - - // award every unique letter until 5 repetitions - var letters = {}; - for (var i=0; i<pass.length; i++) { - letters[pass[i]] = (letters[pass[i]] || 0) + 1; - score += 5.0 / letters[pass[i]]; - } - - // bonus points for mixing it up - var variations = { - digits: /\d/.test(pass), - lower: /[a-z]/.test(pass), - upper: /[A-Z]/.test(pass), - nonWords: /\W/.test(pass), - } - - var variationCount = 0; - for (var check in variations) { - variationCount += (variations[check] === true) ? 1 : 0; - } - score += (variationCount - 1) * 10; - - return parseInt(score); -} - function mapScope (inputScopeFrom, inputScopeTo, outputScopeFrom, outputScopeTo, value) { var x = (value - inputScopeFrom) / (inputScopeTo - inputScopeFrom); var result = outputScopeFrom + ((outputScopeTo - outputScopeFrom) * x); |
