c++用户登录注册系统

用户登录注册
#include "stdafx.h"
#include "iostream"
#include "string"
#include "stdlib.h"
#include "string"
#include "conio.h"
#include "fstream"
#include "windows.h"
using namespace std;
struct user
{
string name;
string password;
};
void nterface(user custum);
int main()
{
void login();
void regist();
int options;
cout << endl << endl << endl << endl;
cout << " 1.登录" << endl;
cout << " 2.注册" << endl;
cout << " (请输入选项并按回车)" << endl;
cout << " ";
cin >> options;
while (options!=1&&options!=2)
{
cout << " erro,请重新输入:";
cin >> options;
}
cout << options;
if (options ==1)
{
system("CLS");
login();
}
if (options == 2)
{
system("CLS");
regist();
system("CLS");
login();
}
return 0;
}
void login()
{
string name;
char *password = new char[20];
cout << endl << endl << endl << endl << endl;
cout << " 用户名:";
cin >> name;
cout << " 密码:";
char test='a'; int i = 0;
while ((test=_getch())!='\r')
{
if (test == 8)
{
if (i > 0)
{
cout << test << " " << test;
password[i--] = '\0';
}
}
else
{
if (i < 20)
{
cout << "*";
password[i] = test;
i++;
}
}
}
password[i] = '\0';
ifstream fin;
fin.open("",ios_base::in);
if (fin.fail())
{
cout << "打开文件失败" <<endl;
}
user custumer;
while (fin >> custumer.name >> custumer.password)
{
if (custumer.name == name&&custumer.password == password)
{
cout << "登录成功!" <<endl;
nterface(custumer);
}
}
if (!(fin >> custumer.name >> custumer.password))
{
}
else
{
cout<<endl << "用户名或密码错误!!!" << endl;
Sleep(3000);
system("CLS");
login();
}
}
void regist()
{
string name;
char *password = new char[20];
cout << endl << endl << endl << endl << endl;
ifstream fin;
fin.open("", ios_base::in);
user custumer;
int i = 0;
cout << " 新建用户名:";
cin >> name;
while (fin >> custumer.name >> custumer.password)
{
if (custumer.name == name) i++;
}
if (i > 0)
{
cout << "该用户名已被注册@!" << endl; regist();
}
cout << " 输入密码:";
char test = 'a'; i = 0;
while ((test = _getch()) != '\r')
{
if (test == 8)
{
if (i > 0)
{
cout << test << " " << test;
password[i--] = '\0';
}
}
else
{
if (i < 20)
{
cout << "*";
password[i] = test;
i++;
}
}
}
password[i] = '\0';
cout << " 再次输入密码:";
char *password2 = new char[20];
test = 'a'; i = 0;
while ((test = _getch()) != '\r')
{
if (test == 8)
{
if (i > 0)
{
cout << test << " " << test;
password2[i--] = '\0';
}
}
else
{
if (i < 20)
{
cout << "*";
password2[i] = test;
i++;
}
}
}
password2[i] = '\0';
if (strcmp(password,password2)!=0)
{
cout <<endl<<" 两次输入密码不一致,请重新注册。。。" << endl;
Sleep(3000);
system("CLS");
regist();
}
else
cout<<endl<< " 注册成功!撸一发庆祝一下";
ofstream fout;
fout.open("",ios_base::out|ios_base::app);
fout << name << " " << password << endl;
fout.close();
cout<<endl<< " 3秒后跳到登录界面...........";
Sleep(3000);
}
void nterface(user custum)
{
system("CLS");
cout << "您好!"<<custum.name << endl<<endl;
}

本文发布于:2024-09-26 01:26:01,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/824885.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:输入   密码   登录   用户名
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议