密码程序
Password program
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{
fstream fin;
string password;
cout << "Please enter your password!" << endl;
cin >> password;
fin.open("Text.txt");
int nlen = password.length();
if (nlen <= 7)
return false;
if (nlen >= 8)
return true;
bool hasUpp = false;
bool hasLow = false;
bool hasDig = false;
bool hasSym = false;
for (int i = 0; i < nlen; i++)
{
if (isupper(password[i]))
hasUpp = true;
if (islower(password[i]))
hasLow = true;
if (isdigit(password[i]))
hasDig = true;
}
if (hasLow && hasUpp && hasDig && hasSym)
{
return true;
}
else
{
return false;
}
if (hasLow && hasUpp && hasDig && hasSym)
{
cout << "Your password is strong! " << endl;
}
else
{
cout << "Your password is too weak! " << endl;
}
cin.get();
cin.get();
return 0;
}
该程序应该从用户那里获取输入数据,并确定它是否是一个有点强的密码。我意识到这还没有接近完成。我遇到的问题是让程序读取我的输入文件并弄清楚输入文件中的任何单词是否作为密码输入,然后告诉他们他们的密码是错误的。
我对你的程序进行了一些修改,使其至少可以处理用户输入数据。您可能想知道为什么没有从程序中获得任何输出?程序中有两个 if 子句会导致 main(( 函数返回(= 应用程序终止(:
if (nlen <= 7)
return false;
if (nlen >= 8)
return true;
调用其中一个 return 语句是因为其中一个 if 子句始终为真,因此您的程序将退出该语句。
以下是处理用户输入的单个密码的修改代码:
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{
string password;
cout << "Please enter your password!" << endl;
cin >> password;
int nlen = password.length();
bool hasUpp = false;
bool hasLow = false;
bool hasDig = false;
bool hasSym = false;
bool isLong = false;
if (nlen >= 8)
isLong = false;
for (int i = 0; i < nlen; i++)
{
if (isupper(password[i]))
hasUpp = true;
if (islower(password[i]))
hasLow = true;
if (isdigit(password[i]))
hasDig = true;
}
if (hasLow && hasUpp && hasDig && hasSym && isLong)
{
cout << "Your password is strong! " << endl;
}
else
{
cout << "Your password is too weak! " << endl;
}
cin.get();
cin.get();
return 0;
}
要将其扩展为从文件中读取多个密码,您必须逐行读取文件(如此处所述(并处理每一行。
**YOU CAN DO LIKE THIS**
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
void gotox(int x)
{
COORD xy = {0, 0};
xy.X = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy);
}
void getx(int &x) {
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
x = csbi.dwCursorPosition.X;
}
}
int main()
{
SetConsoleTitle("file password protector");
char pas;
string password = "";
int x,t = 0;
cout<<"enter password : ";
do
{
pas = _getch();
switch(int(pas))
{
case 8: getx(x);
if(x>17)
{
--x;
gotox(x);
cout<<" ";
if(password.length()>0){password.erase(password.length()-1,1);}
--t;
gotox(x);
}
break;
case 27: return 0;
case 13: if(t>8)
{
pass = 27
}
break;
default :if(t < 30)
{
if(int(pas)>0)
{
password.push_back(pas);cout<<"*";++t;
}
else
{
pas = _getch();
}
}}}while(pas != 13);
bool hasUpp = false;
bool hasLow = false;
bool hasDig = false;
bool hasSym = false;
for (int i = 0; i < t; i++)
{
if (isupper(password[i]))
hasUpp = true;
if (islower(password[i]))
hasLow = true;
if (isdigit(password[i]))
hasDig = true;
}
if (hasLow && hasUpp && hasDig && hasSym)
{
cout << "Your password is strong! " << endl;
}
else
{
cout << "Your password is too weak! " << endl;
}
_getch();
return 0;
}
相关文章:
- 密码登录程序将永远循环并显示不正确的结果
- 如何在C++的凯撒密码程序中包含空格?
- 即使密码/用户无效,程序仍会继续
- 程序输入密码并解锁窗口7,8,10
- 凯撒密码程序中"Debug Assertion Failed!"问题
- Atbash 密码程序 A = Z, B = Y, C = X
- 密码验证程序
- C++应用程序连接到网站服务器并根据密码检索文件
- 如何制作一个从文件中读取密码并与用户编写的密码进行比较的 c++ 程序
- 简单的密码哈希程序 c++
- 在我的C++凯撒密码程序中出现错误
- 凯撒密码程序
- 在CPP应用程序中保存密码
- 制作需要接受字母和数字组合的密码类型程序
- 在c++登录程序中屏蔽密码
- 程序的密码
- 转录密码加密程序崩溃
- 密码检查程序-匹配密码失败-循环失败
- C++ 密码程序上的计数循环
- 密码验证程序