Use zxcvbn for password strength estimation

This commit is contained in:
moneromooo.monero
2016-12-16 00:11:37 +00:00
parent b882de8e1c
commit fbe19d23b7
4 changed files with 20 additions and 33 deletions

View File

@@ -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();