⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 password.h

📁 小型图书馆管理系统
💻 H
字号:
#ifndef PASSWORD_H
#define PASSWORD_H
#include"administrator.h"

//*****************************************************************************
//*                        Password(修改密码)函数                           *
//*****************************************************************************

void Password(char *name,int authority)
{
	Administrator *limits,*p;
	fstream dataFile;
	char pwd[30],pw[7];
	int times=1;
	
	if(authority==1)
	{
		dataFile.open("Advanced.dat",ios::in);
		if(!dataFile)
		{
			cout<<"          高级管理员文件出现错误,程序中止!"<<endl;
			cin.get();
			return;
		}
		limits=new Administrator;
		
		while(!dataFile.eof())
		{
			p=new Administrator;
			dataFile>>p->name;
			dataFile>>p->password;
			p->next=limits->next;
			limits->next=p;
		}    //读取高级管理员资料至类变量
		dataFile.close();
	}
	else
	{
		dataFile.open("Common.dat",ios::in);
		if(!dataFile)
		{
			cout<<"          普通管理员文件出现错误,程序中止!"<<endl;
			cin.get();
			return;
		}
		limits=new Administrator;
		
		while(!dataFile.eof())
		{
			p=new Administrator;
			dataFile>>p->name;
			dataFile>>p->password;
			p->next=limits->next;
			limits->next=p;
		}    //读取普通管理员资料至类变量
		dataFile.close();
	}
	for(p=limits->next;p;p=p->next)
		if(strcmp(p->name,name)==0)
		{
			system("cls");
			cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
			cout<<"                         请输入新的六位密码:";
			cin>>pwd;
			cout<<endl;
			
			while(strlen(pwd)!=6)
			{
				cout<<"                        密码为六位,请重新输入:";
				cin>>pwd;
				cout<<endl;
			}
			strcpy(pw,pwd);
			cout<<"                         请再次输入六位密码:";
			cin>>pwd;
			cout<<endl;

			while(strcmp(pw,pwd)!=0)
			{
				cout<<"                    两次输入不一致,请重新输入:";
				cin>>pwd;
				cout<<endl;
				if(strcmp(pw,pwd)!=0 && ++times==3)
				{
					cout<<endl<<"                     密码修改失败,按回车键返回主菜单。";
					cin.ignore();
					cin.get();
					return;
				}
			}
			strcpy(p->password,pw);
			cout<<endl<<"                     新密码已确认,按回车键返回主菜单。";
			cin.ignore();
			cin.get();
			break;
		}
	if(authority==1)
	{
		dataFile.open("Advanced.dat",ios::out);
		for(p=limits->next->next;p;p=p->next)
		{
			dataFile<<p->name<<endl;
			dataFile<<p->password<<endl;
		}                //写入高级管理员文件
	}
	else
	{
		dataFile.open("Common.dat",ios::out);
		for(p=limits->next->next;p;p=p->next)
		{
			dataFile<<p->name<<endl;
			dataFile<<p->password<<endl;
		}                //写入普通管理员文件
	}
	return;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -