Added 2 new password generator options

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@227 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 16 years ago
parent 598d204716
commit a5d427d262
  1. 2
      changelog
  2. 5
      src/Kdb3Database.cpp
  3. 4
      src/KpxConfig.h
  4. 2
      src/crypto/twoclass.cpp
  5. 158
      src/dialogs/PasswordGenDlg.cpp
  6. 8
      src/dialogs/PasswordGenDlg.h
  7. 28
      src/forms/PasswordGenDlg.ui
  8. 1
      src/lib/EntryView.cpp
  9. 2
      src/lib/SecString.cpp
  10. 8
      src/lib/random.cpp
  11. 4
      src/lib/random.h
  12. 2
      src/mainwindow.cpp

@ -1,7 +1,7 @@
----------------------------
0.3.3 (2008-08-11)
----------------------------
- fix an error when opening twofish encrypted databases
- fixed error when opening twofish encrypted databases (Bug #2025075)
----------------------------
0.3.2 (2008-07-20)

@ -1614,10 +1614,7 @@ void Kdb3Database::create(){
RootGroup.Parent=NULL;
RootGroup.Handle=NULL;
Algorithm=Rijndael_Cipher;
quint16 ran;
randomize(&ran,2);
ran &= 0x03FF; // only use 10 bits -> max 1024
KeyTransfRounds=10000 + ran;
KeyTransfRounds=50000;
KeyError=false;
}

@ -75,6 +75,8 @@ public:
bool autoSaveChange(){return settings.value("Options/AutoSaveChange",false).toBool();}
int pwGenCategory(){return settings.value("Options/PwGenCategory",0).toInt();}
QString pwGenCharList(){return settings.value("Options/PwGenCharList").toString();}
bool pwGenExcludeLookAlike(){return settings.value("Options/PwGenExcludeLookAlike").toBool();}
bool pwGenEveryGroup(){return settings.value("Options/PwGenEveryGroup").toBool();}
int pwGenLength(){return settings.value("Options/PwGenLength",25).toInt();}
QBitArray pwGenOptions(){return stringToBitArray(settings.value("Options/PwGenOptions","11111000011110").toString(),14);}
bool rememberLastKey(){return settings.value("Options/RememberLastKey",true).toBool();}
@ -136,6 +138,8 @@ public:
void setAutoSaveChange(bool value){settings.setValue("Options/AutoSaveChange",value);}
void setPwGenCategory(int value){settings.setValue("Options/PwGenCategory",value);}
void setPwGenCharList(const QString& value){settings.setValue("Options/PwGenCharList",value);}
void setPwGenExcludeLookAlike(bool value){settings.setValue("Options/PwGenExcludeLookAlike",value);}
void setPwGenEveryGroup(bool value){settings.setValue("Options/PwGenEveryGroup",value);}
void setPwGenLength(int value){settings.setValue("Options/PwGenLength",value);}
void setPwGenOptions(const QBitArray& value){settings.setValue("Options/PwGenOptions",bitArrayToString(value));}
void setRememberLastKey(bool value){settings.setValue("Options/RememberLastKey",value);}

@ -18,7 +18,7 @@
***************************************************************************/
#include <qstring.h>
#include <QString>
#include "twoclass.h"
static bool g_bInitialized = false;

@ -22,6 +22,7 @@
#include "dialogs/PasswordGenDlg.h"
#include "dialogs/CollectEntropyDlg.h"
#include "random.h"
#include "apg/randpass.h"
#include "apg/pronpass.h"
@ -109,6 +110,8 @@ CGenPwDialog::CGenPwDialog(QWidget* parent, bool StandAloneMode,Qt::WFlags fl)
checkBoxPN->setChecked(true);
checkBoxPS->setChecked(false);
}
Check_ExcludeLookAlike->setChecked(config->pwGenExcludeLookAlike());
Check_EveryGroup->setChecked(config->pwGenEveryGroup());
Spin_Num->setValue(config->pwGenLength());
adjustSize();
setMaximumSize(size());
@ -139,6 +142,8 @@ CGenPwDialog::~CGenPwDialog(){
pwGenOptions.setBit(12,checkBoxPN->isChecked());
pwGenOptions.setBit(13,checkBoxPS->isChecked());
config->setPwGenOptions(pwGenOptions);
config->setPwGenExcludeLookAlike(Check_ExcludeLookAlike->isChecked());
config->setPwGenEveryGroup(Check_EveryGroup->isChecked());
config->setPwGenLength(Spin_Num->value());
}
@ -198,21 +203,6 @@ void CGenPwDialog::OnGeneratePw()
gen_pron_pass(buffer, hyphenated_word, length, length, mode);
delete[] hyphenated_word;
}
else if (Radio_1->isChecked() && !checkBox5->isChecked() &&
!checkBox6->isChecked() && !checkBox7->isChecked())
{
unsigned int mode = 0;
if (checkBox1->isChecked())
mode |= S_CL;
if (checkBox2->isChecked())
mode |= S_SL;
if (checkBox3->isChecked())
mode |= S_NB;
if (checkBox4->isChecked())
mode |= S_SS;
gen_rand_pass(buffer, length, length, mode);
}
else{
generatePasswordInternal(buffer, length);
}
@ -221,24 +211,6 @@ void CGenPwDialog::OnGeneratePw()
delete[] buffer;
}
int CGenPwDialog::AddToAssoctable(char* table,int start,int end,int pos){
for(int i=start;i<=end;i++){
table[pos]=i;
pos++;
}
return (end-start)+1;
}
bool CGenPwDialog::trim(unsigned char &x, int r){
if(x<r)
return true;
if(256%r!=0)
return false;
x=x-(x/r)*r;
return true;
}
void CGenPwDialog::estimateQuality(){
int num=0;
if (tabCategory->currentIndex()==0){
@ -340,6 +312,32 @@ void CGenPwDialog::SwapEchoMode(){
}
}
void CGenPwDialog::AddToAssoctable(char* table,int start,int end,int& pos){
for (int i=start;i<=end;i++){
if (Check_ExcludeLookAlike->isChecked()){
switch (i){
case 48: // 0
case 79: // O
case 49: // 1
case 73: // I
case 108: // l
case 124: // |
continue;
}
}
table[pos]=i;
pos++;
}
}
CGenPwDialog::PwGroup CGenPwDialog::AddToAssoctableGroup(char* table,int start,int end,int& pos){
PwGroup group;
group.start = pos;
AddToAssoctable(table,start,end,pos);
group.end = pos-1;
return group;
}
void CGenPwDialog::generatePasswordInternal(char* buffer, int length){
/*-------------------------------------------------------
ASCII
@ -355,26 +353,62 @@ void CGenPwDialog::generatePasswordInternal(char* buffer, int length){
int num=0;
char assoctable[255];
int groups=0;
bool ensureEveryGroup = false;
QList<PwGroup> groupTable;
if(Radio_1->isChecked()){
if(checkBox1->isChecked())
num+=AddToAssoctable(assoctable,65,90,num);
if(checkBox2->isChecked())
num+=AddToAssoctable(assoctable,97,122,num);
if(checkBox3->isChecked())
num+=AddToAssoctable(assoctable,48,57,num);
if (Check_EveryGroup->isChecked()){
if (checkBox1->isChecked()) groups++;
if (checkBox2->isChecked()) groups++;
if (checkBox3->isChecked()) groups++;
if (checkBox4->isChecked()) groups++;
if (checkBox5->isChecked()) groups++;
if (checkBox6->isChecked()) groups++;
if (checkBox7->isChecked()) groups++;
if (groups<=length)
ensureEveryGroup = true;
}
if(checkBox1->isChecked()){
if (ensureEveryGroup) groupTable.append(AddToAssoctableGroup(assoctable,65,90,num));
else AddToAssoctable(assoctable,65,90,num);
}
if(checkBox2->isChecked()){
if (ensureEveryGroup) groupTable.append(AddToAssoctableGroup(assoctable,97,122,num));
else AddToAssoctable(assoctable,97,122,num);
}
if(checkBox3->isChecked()){
if (ensureEveryGroup) groupTable.append(AddToAssoctableGroup(assoctable,48,57,num));
else AddToAssoctable(assoctable,48,57,num);
}
if(checkBox4->isChecked()){
num+=AddToAssoctable(assoctable,33,47,num);
num+=AddToAssoctable(assoctable,58,64,num);
num+=AddToAssoctable(assoctable,91,96,num);
num+=AddToAssoctable(assoctable,123,126,num);
PwGroup group;
group.start = num;
AddToAssoctable(assoctable,33,44,num);
AddToAssoctable(assoctable,46,47,num);
AddToAssoctable(assoctable,58,64,num);
AddToAssoctable(assoctable,91,94,num);
AddToAssoctable(assoctable,96,96,num);
AddToAssoctable(assoctable,123,126,num);
if (ensureEveryGroup){
group.end = num-1;
groupTable.append(group);
}
}
if(checkBox5->isChecked()){
if (ensureEveryGroup) groupTable.append(AddToAssoctableGroup(assoctable,32,32,num));
else AddToAssoctable(assoctable,32,32,num);
}
if(checkBox6->isChecked()){
if (ensureEveryGroup) groupTable.append(AddToAssoctableGroup(assoctable,45,45,num));
else AddToAssoctable(assoctable,45,45,num);
}
if(checkBox7->isChecked()){
if (ensureEveryGroup) groupTable.append(AddToAssoctableGroup(assoctable,95,95,num));
else AddToAssoctable(assoctable,95,95,num);
}
if(checkBox5->isChecked())
num+=AddToAssoctable(assoctable,32,32,num);
if(checkBox6->isChecked() && !checkBox4->isChecked())
num+=AddToAssoctable(assoctable,45,45,num);
if(checkBox7->isChecked() && !checkBox4->isChecked())
num+=AddToAssoctable(assoctable,95,95,num);
}
else{
QString str=Edit_chars->text();
@ -394,13 +428,29 @@ void CGenPwDialog::generatePasswordInternal(char* buffer, int length){
}
}
unsigned char tmp;
for(int i=0;i<length;i++){
if (ensureEveryGroup){
QList<int> charPos;
for (int i=0; i<length; i++)
charPos.append(i);
do randomize(&tmp,1);
while(!trim(tmp,num));
for (int i=0; i<groups; i++){
int posIndex = randintRange(0, charPos.count()-1);
int pos = charPos[posIndex];
charPos.removeAt(posIndex);
buffer[pos] = assoctable[randintRange(groupTable[i].start, groupTable[i].end)];
}
buffer[i]=assoctable[tmp];
for (int i=groups; i<length; i++){
int posIndex = randintRange(0, charPos.count()-1);
int pos = charPos[posIndex];
charPos.removeAt(posIndex);
buffer[pos] = assoctable[randint(num)];
}
}
else{
qDebug("ja");
for (int i=0; i<length; i++)
buffer[i] = assoctable[randint(num)];
}
}

@ -32,8 +32,12 @@ class CGenPwDialog : public QDialog, public Ui_GenPwDlg
~CGenPwDialog();
private:
int AddToAssoctable(char* table,int start,int end,int pos);
bool trim(unsigned char &value,int range);
struct PwGroup {
int start;
int end;
};
void AddToAssoctable(char* table,int start,int end,int& pos);
PwGroup AddToAssoctableGroup(char* table,int start,int end,int& pos);
void paintEvent(QPaintEvent* event);
void generatePasswordInternal(char* buffer, int length);
QPixmap BannerPixmap;

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>462</width>
<height>491</height>
<height>543</height>
</rect>
</property>
<property name="windowTitle" >
@ -43,7 +43,7 @@
<x>0</x>
<y>0</y>
<width>440</width>
<height>219</height>
<height>271</height>
</rect>
</property>
<attribute name="title" >
@ -102,7 +102,7 @@
<item row="2" column="1" >
<widget class="QCheckBox" name="checkBox7" >
<property name="text" >
<string>U&amp;nderline</string>
<string>&amp;Underline</string>
</property>
<property name="shortcut" >
<string>Alt+N</string>
@ -125,7 +125,7 @@
<item row="0" column="1" >
<widget class="QCheckBox" name="checkBox5" >
<property name="text" >
<string>White &amp;Spaces</string>
<string>&amp;White Spaces</string>
</property>
<property name="shortcut" >
<string>Alt+S</string>
@ -148,7 +148,7 @@
<item row="1" column="1" >
<widget class="QCheckBox" name="checkBox6" >
<property name="text" >
<string>Minus</string>
<string>&amp;Minus</string>
</property>
</widget>
</item>
@ -219,6 +219,20 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="Check_ExcludeLookAlike" >
<property name="text" >
<string>Exclude look-alike characters</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="Check_EveryGroup" >
<property name="text" >
<string>Ensure that password contains characters from every group</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabPronounceable" >
@ -227,7 +241,7 @@
<x>0</x>
<y>0</y>
<width>440</width>
<height>219</height>
<height>271</height>
</rect>
</property>
<attribute name="title" >
@ -250,7 +264,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<layout class="QGridLayout" name="gridLayout" >
<layout class="QGridLayout" name="gridLayout_2" >
<property name="spacing" >
<number>15</number>
</property>

@ -274,6 +274,7 @@ void KeepassEntryView::OnEditOpenUrl(){
void KeepassEntryView::OnEditCopyUrl(){
if (selectedItems().size() == 0) return;
QString url = ((EntryViewItem*)selectedItems().first())->EntryHandle->url();
if (url.trimmed().isEmpty()) return;
if (url.startsWith("cmd://") && url.length()>6)
url = url.right(url.length()-6);

@ -126,7 +126,7 @@ void SecData::unlock(){
}
void SecData::copyData(quint8* src){
unlock();
locked = false;
memcpy(data, src, length);
lock();
}

@ -47,10 +47,14 @@ void getEntropy(quint8* buffer, int length){
}
}
quint32 randint(quint32 n){
quint32 randint(quint32 limit){
quint32 rand;
randomize(&rand, 4);
return (rand % n);
return (rand % limit);
}
quint32 randintRange(quint32 min, quint32 max){
return min + randint(max-min+1);
}
#if defined(Q_WS_X11) || defined(Q_WS_MAC)

@ -33,10 +33,12 @@ extern "C" {
#endif
void getEntropy(quint8* buffer, int length);
quint32 randint(quint32 n);
quint32 randint(quint32 limit); // generate random number: 0 <= n < limit
#ifdef __cplusplus
}
#endif
quint32 randintRange(quint32 min, quint32 max); // generate random number: min <= n <= max
#endif

@ -354,6 +354,7 @@ void KeepassMainWindow::setupMenus(){
EditPasswordToClipboardAction->setShortcut(tr("Ctrl+C"));
EditUsernameToClipboardAction->setShortcut(tr("Ctrl+B"));
EditOpenUrlAction->setShortcut(tr("Ctrl+U"));
EditCopyUrlAction->setShortcut(tr("Ctrl+I"));
EditNewEntryAction->setShortcut(tr("Ctrl+Y"));
EditEditEntryAction->setShortcut(tr("Ctrl+E"));
EditDeleteEntryAction->setShortcut(tr("Ctrl+D"));
@ -630,7 +631,6 @@ void KeepassMainWindow::setStateFileOpen(bool IsOpen){
void KeepassMainWindow::setStateFileModified(bool mod){
if (config->autoSaveChange() && mod && db->file()){
OnFileSave();
mod = false;
}
ModFlag=mod;