密码验证程序
Password verifier
所以我尝试了许多不同的方法,但无法让它运行第一个if语句,也无法打印出每个问题。 我的问题是是否可以在不使用函数的情况下做到这一点?如果是这样,请您帮助我修复我的代码,以便它正常工作或至少引导我朝着正确的方向前进。我觉得这段代码缺少一两个关键部分,我无法理解它。
******更新版本****
(仍然行不通(
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
using namespace std;
//Create program that verifies that a password meets certain criteria.The
//password must :
//-Be at least eight characters long
//- Contain an uppercase letter
//- Contain a lowercase letter
//- Contain a numeric digit
//Prompt the user to enter a password and then verify it.Your program should
//list every issue the password has.
int main()
{
cout << "**************************************************** n";
cout << "Your password must be characters long and containt: n";
cout << "An uppercase letter. n";
cout << "A lowercase letter. n";
cout << "And a number. n";
cout << "**************************************************** n";
cout << " n";
const int size = 200;
char pass1[size], pass2[size];
const unsigned int password_length = 8U;
unsigned int length = 0;
bool has_lower_case_letter = false;
bool has_digit = false;
bool has_upper_case_letter = false;
char password[password_length + 1];
cout << "Please enter a password: ";
cin >> pass1;
while (length < password_length)
{
if (!has_lower_case_letter)
{
static const char lower_case_letters[] = "abcdefghijklmnopqrstuvwxyz";
static const int letter_quantity =
sizeof(lower_case_letters) / sizeof(lower_case_letters[0]);
for (int i = 0; i < letter_quantity; ++i)
{
if (pass1[size] == lower_case_letters[i])
{
has_lower_case_letter = true;
break;
}
}
}
if (!has_upper_case_letter)
{
static const char upper_case_letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const int letter_quantity =
sizeof(upper_case_letters) / sizeof(upper_case_letters[0]);
for (int i = 0; i < letter_quantity; ++i)
{
if (pass1[size] == upper_case_letters[i])
{
has_upper_case_letter = true;
}
}
}
if (!has_upper_case_letter)
{
static const char digits[] = "0123456789";
static const int digit_quantity =
sizeof(digits) / sizeof(digits[0]);
for (int i = 0; i < digit_quantity; ++i)
{
if (pass1[size] == digits[i])
{
has_digit = true;
}
}
}
password[length] = pass1[size];
++length;
}
if (!has_digit)
cout << "The password must contain a digit. n";
if (!has_upper_case_letter)
cout << "The password must include an uppercase letter. n";
if (!has_lower_case_letter)
cout << "The password must include a lowercase letter. n";
return 0;
}
你不能
在没有函数的情况下编写程序,因为main
是一个函数,你正在使用一个函数来获取用户的输入。
也就是说,是的,您可以在不使用搜索函数的情况下检查文本字符串。
const unsigned int password_length = 8U;
unsigned int length = 0;
bool has_lower_case_letter = false;
bool has_digit = false;
bool has_upper_case_letter = false;
char password[password_length + 1];
while (length < password_length)
{
char c;
cin >> c;
if (!has_lower_case_letter)
{
static const char lower_case_letters[] = "abcdefghijklmnopqrstuvwxyz"
static const letter_quantity =
sizeof(lower_case_letters) / sizeof(lower_case_letters[0]);
for (unsigned int i = 0; i < letter_quantity; ++i)
{
if (c == lower_case_letters[i])
{
has_lower_case_letter = true;
break;
}
}
}
//...
password[length] = c;
++length;
}
大写字母和数字的检查留给海报作为练习。
相关文章:
- 如何让我的程序在输入验证的基础上读取素数
- 从 c++ 应用程序中删除应用程序验证程序
- OpenGL 着色器程序无法验证,但不提供错误消息
- 程序终止,而不是继续整数输入验证循环
- 使用 gtest 和 gmock 验证程序调用
- C 链接的列表用户输入限制验证导致程序结束
- 密码验证程序
- 如何修复在 Linux 内核 SPI 驱动程序中始终无法验证的 SPI 驱动程序
- 程序不输出正确的标准偏差.另外,验证问题
- 如何验证视频卡驱动程序证书
- 基于局域网的应用程序和安全通道身份验证
- 平面缓冲区验证程序行为
- 我该如何验证给定类的每个实例都被应用程序终止所破坏
- 使用应用程序验证程序调试时应用程序挂起
- 如何在 Visual Studio 2013 中使用带/不带Microsoft应用程序验证程序的调试
- 如何使用Microsoft应用程序验证程序
- 无效句柄(使用应用程序验证程序)
- 在哪里可以运行应用程序验证程序命令
- 应用程序验证器DEBUG或RELEASE模式
- 应用程序验证程序不允许启动我的应用程序