-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword.cpp
More file actions
58 lines (52 loc) · 1.86 KB
/
password.cpp
File metadata and controls
58 lines (52 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "password.h"
#include <QtSql>
#include <cstdlib>
#include <ctime>
static const char alphanum[]="0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength=sizeof(alphanum)-1;
Password::Password():characters("*****")
{
}
void Password::addNewEntry(QString newTitle, QString newUserName, QString newPassword, QString newNotes, QString newURL,QString gID, QString id)
{
//validation required!!!!!!
title=newTitle; userName=newUserName; password=newPassword; notes=newNotes; url=newURL;dbID=id;groupID=gID;
QSqlQuery add;
add.prepare("insert into passwords(title,userName,password,notes,url,dbID,groupID,creationTime,modificationTime,hide)"
"values('"+title+"','"+userName+"','"+password+"','"+notes+"','"+url+"','"+dbID+"','"+groupID+"',GETDATE(),GETDATE(),'"+characters+"')");
if(add.exec())
qDebug()<<"Password Entry added...";
else
qDebug()<<"Password Entry not added..."<<add.lastError().text();
}
void Password::editEntry(QString newTitle, QString newUserName, QString newPassword, QString newNotes, QString newURL, QString id)
{
//validation required!!!!!!
title=newTitle; userName=newUserName; password=newPassword; notes=newNotes; url=newURL;passID=id;
QSqlQuery edit;
edit.prepare("update passwords set title='"+title+"',userName='"+userName+"',password='"+password+"',notes='"+notes+"',url='"+url+"',modificationTime=GETDATE() where passID='"+id+"'");
if(edit.exec())
{
qDebug()<<"Password Entry edited...";
}
else
{
qDebug()<<"Password Entry not edited..."<<edit.lastError().text();
}
}
char Password::generateRandom()
{
return alphanum[rand()%stringLength];
}
QString Password::generatePassword()
{
srand(time(0));
QString Str;
for(int i=0;i<10;i++)
{
Str+=generateRandom();
}
return Str;
}