资源简介
1.使用C++实现的权限管理模块
2.单例模式实现,方便集成
3.实现了root和普通用户区别,添加新用户,修改密码
4.用户名密码以加密文档形式存在本地文件

代码片段和文件信息
#include “stdafx.h“
#include “AuthorityManagement.h“
namespace cis
{
//using singleton
AuthorityManagement* AuthorityManagement::instance = new AuthorityManagement();
AuthorityManagement* AuthorityManagement::getInstance()
{
return instance;
}
AuthorityManagement::AuthorityManagement()
{
m_Key = “dasidaiousdadfkjdhIJpqwieTGYU“;
m_isInitialized = false;
}
AuthorityManagement::~AuthorityManagement()
{
}
int AuthorityManagement::Initialization()
{
//打开存放用户信息的txt
ifstream readUserInfo;
readUserInfo.open(“UserInfo.txt“);
if (!readUserInfo.is_open())
{
return 0;
}
//从txt中读入用户信息
string userName;
string password;
while (getline(readUserInfo userName))
{
decrypt(userName);
getline(readUserInfo password);
decrypt(password);
m_UserInfo[userName] = password;
}
//关闭ifstream
readUserInfo.close();
m_isInitialized = true;
return 1;
}
string AuthorityManagement::getCurrentUser()
{
return m_CurrentUser;
}
int AuthorityManagement::logout()
{
m_CurrentUser.clear();
return 1;
}
int AuthorityManagement::signIn(string userName string password)
{
//必须在权限管理模块初始化完成后才能登录
if (!m_isInitialized)
{
return false;
}
//首先检查是否存在用户名
if (m_UserInfo.count(userName))
{
//如果密码正确就能登录系统
if (m_UserInfo[userName] == password)
{
m_CurrentUser = userName;
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
int AuthorityManagement::addUser(string userName string password)
{
//必须在权限管理模块初始化完成后才能登录
if (!m_isInitialized)
{
return false;
}
//非管理员没有权限添加新用户
if (m_CurrentUser!=“root“)
{
return false;
}
//禁止添加相同用户名的用户
if (m_UserInfo.count(userName))
{
return false;
}
ofstream writeUserInfo;
//打开文件以追加方式打开
writeUserInfo.open(“UserInfo.txt“ ios_base::app);
if (!writeUserInfo.is_open())
{
return false;
}
string cipherUserName = userName;
encrypt(cipherUserName);
string cipherPassword = password;
encrypt(cipherPassword);
writeUserInfo << cipherUserName << endl;
writeUserInfo << cipherPassword << endl;
writeUserInfo.close();
m_UserInfo[userName] = password;
return true;
}
int AuthorityManagement::addRoot(string password)
{
ofstream writeUserInfo;
//打开文件以追加方式打开
writeUserInfo.open(“UserInfo.txt“);
if (!writeUserInfo.is_open())
{
return false;
}
string cipherUserName = “root“;
encrypt(cipherUserName);
string cipherPassword = password;
encrypt(cipherPassword);
writeUserInfo << cipherUserName << endl;
writeUserInfo << cipherPassword << endl;
writeUserInfo.close();
m_UserInfo[“root“] = password;
return true;
}
int AuthorityManagement::modifyPassword(string password)
{
//必须在权限管理模块初始化完成后才能登录
if (!m_isInitialized)
{
return false;
}
//必须在登录的情况下才能修改密码
if (!m_CurrentUser.size())
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4764 2018-05-25 21:24 testAuthorityManagement\AuthorityManagement.cpp
文件 1183 2018-05-25 20:43 testAuthorityManagement\AuthorityManagement.h
文件 1169 2018-05-25 20:41 testAuthorityManagement\testAuthorityManagement.cpp
目录 0 2018-05-25 21:29 testAuthorityManagement
----------- --------- ---------- ----- ----
7116 4
- 上一篇:拼图游戏大型课程设计C# C++
- 下一篇:图书管理系统c++ 数据库
相关资源
- C++获取计算机的CPU ID,硬盘序列号等
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- qt登录富文本编辑器和文档打印设计
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
评论
共有 条评论