Return password quality to keepasshttp client.

This commit is contained in:
Keith Bennett 2014-03-23 01:13:27 +00:00
parent 75564c8fb5
commit b432103b82
5 changed files with 26 additions and 1 deletions

View File

@ -89,6 +89,22 @@ QString PasswordGenerator::generatePassword() const
return password; return password;
} }
int PasswordGenerator::getbits() const
{
QVector<PasswordGroup> groups = passwordGroups();
int bits = 0;
QVector<QChar> passwordChars;
Q_FOREACH (const PasswordGroup& group, groups) {
bits += group.size();
}
bits *= m_length;
return bits;
}
bool PasswordGenerator::isValid() const bool PasswordGenerator::isValid() const
{ {
if (m_classes == 0) { if (m_classes == 0) {

View File

@ -55,6 +55,7 @@ public:
bool isValid() const; bool isValid() const;
QString generatePassword() const; QString generatePassword() const;
int getbits() const;
private: private:
QVector<PasswordGroup> passwordGroups() const; QVector<PasswordGroup> passwordGroups() const;

View File

@ -229,3 +229,8 @@ QString HttpSettings::generatePassword()
return m_generator.generatePassword(); return m_generator.generatePassword();
} }
int HttpSettings::getbits()
{
return m_generator.getbits();
}

View File

@ -60,6 +60,7 @@ public:
static PasswordGenerator::CharClasses passwordCharClasses(); static PasswordGenerator::CharClasses passwordCharClasses();
static PasswordGenerator::GeneratorFlags passwordGeneratorFlags(); static PasswordGenerator::GeneratorFlags passwordGeneratorFlags();
static QString generatePassword(); static QString generatePassword();
static int getbits();
private: private:
static PasswordGenerator m_generator; static PasswordGenerator m_generator;

View File

@ -14,6 +14,7 @@
#include "Server.h" #include "Server.h"
#include <microhttpd.h> #include <microhttpd.h>
#include "Protocol.h" #include "Protocol.h"
#include "HttpSettings.h"
#include "crypto/Crypto.h" #include "crypto/Crypto.h"
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QCryptographicHash> #include <QtCore/QCryptographicHash>
@ -165,11 +166,12 @@ void Server::generatePassword(const Request &r, Response *protocolResp)
return; return;
QString password = generatePassword(); QString password = generatePassword();
QString bits = QString::number(HttpSettings::getbits());
protocolResp->setSuccess(); protocolResp->setSuccess();
protocolResp->setId(r.id()); protocolResp->setId(r.id());
protocolResp->setVerifier(key); protocolResp->setVerifier(key);
protocolResp->setEntries(QList<Entry>() << Entry("generate-password", "generate-password", password, "generate-password")); protocolResp->setEntries(QList<Entry>() << Entry("generate-password", bits, password, "generate-password"));
memset(password.data(), 0, password.length()); memset(password.data(), 0, password.length());
} }