-
Notifications
You must be signed in to change notification settings - Fork 11
/
signup.cpp
132 lines (123 loc) · 2.8 KB
/
signup.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "signup.h"
#include "ui_signup.h"
#include "QFile"
#include "QTextStream"
#include "mainwindow.h"
#include<QDebug>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<fstream>
#include<QFile>
#include<QTextStream>
#include<QDebug>
#include<QMessageBox>
#include "database.h"
signup::signup(QWidget *parent) :
QDialog(parent),
ui(new Ui::signup)
{
ui->setupUi(this);
this->setWindowTitle("SIGNUP");
QPixmap pix("D:\\qt\\irctc3\\logo.jpg");
ui->label_4->setPixmap(pix);
QString filename ="D:\\qt\\irctc3\\user.txt";
QFile file(filename);
if(!file.exists())
{
qDebug() << filename<<"not exits...";
}
else
{
QString line;
if(file.open(QIODevice::ReadOnly|QIODevice::Text))
{
QTextStream stream(&file);
while(!stream.atEnd())
{
line=stream.readLine();
QString name = line.split(" ").at(0);
user[name]="1";
}
}
}
}
signup::~signup()
{
delete ui;
}
void signup :: open_login()
{
log=new login(this);
log->show();
}
QString signup:: encrypted(QString pass)
{
int n=pass.length();
int i;
std::string s=pass.toUtf8().constData();
for(i=0;i<n;i++)
{
if(s[i]=='y')
s[i]='a';
if(s[i]=='Y')
s[i]='A';
if(s[i]=='z')
s[i]='b';
if(s[i]=='Z')
s[i]='B';
else
s[i]=s[i]+2;
}
pass=QString ::fromStdString(s);
return pass;
}
void signup::on_buttonBox_accepted()
{
QString name,pass,mobile;
name=ui->lineEdit->text();
pass=ui->lineEdit_2->text();
mobile=ui->lineEdit_3->text().toInt();
if(name=="" || pass=="")
{
QMessageBox::critical(this,tr("error"),tr("fields are empty"));
}
else
{
if(user[name].compare("1")==0)
{
QMessageBox::critical(this,tr("error"),tr("Sorry, that username is already taken!"));
ui->lineEdit->clear();
ui->lineEdit_2->clear();
ui->lineEdit_3->clear();
}
else
{
pass=encrypted(pass);
QString filename="D:\\qt\\irctc3\\user.txt";
QFile file(filename);
if(!file.exists()){
qDebug() << "NO exist "<<filename;
}else{
qDebug() << filename<<" exits...";
}
QTextStream out(&file);
file.open(QFile::ReadWrite | QFile::Append);
out<<"\n"<<name<<" ";
out<<pass<<" ";
file.close();
this->hide();
open_login();
}
}
}
void signup::on_buttonBox_rejected()
{
ui->lineEdit->clear();
ui->lineEdit_2->clear();
ui->lineEdit_3->clear();
}
void signup::on_pushButton_clicked()
{
exit(0);
}