编程密码函数模板
programming password function template
您好,我正在尝试使用 c++ 创建一个密码函数,最多可以处理 12 个字符,并且可以调用三个单独的布尔函数:isUpper、isLower、IsPunctuation。
有什么建议或模板可以开始吗?我想把这部分排除在外,继续我的程序。谢谢你的帮助。
这是我到目前为止所拥有的:
#include<iostream.h>
#include<conio.h>
#include<string.h>
char enterPass();
void passFunc();
char enterPass() {
char numPass[12];
char ch;
int i=0;
while((ch!='r')||(ch!='n')&&(i!=11)) {
cin>>ch; cout<<'*'; numPass[i]=ch; i++;
}
return numPass[12];
}
void passFunc() {
char pass[12];
cout<<"Enter password :- ";
pass=enterPass();
if(strcmp(pass,"myworld")==0) {
cout<<"Correct Password"; getch();
} else {
cout<<"Wrong Password";
exit(0);
}
}
int main() {
passFunc();
getch();
return 0;
}
您可能希望开始对代码进行轻微(教学)修改:
#include <iostream>
using namespace std;
void enterPass(char* numPass)
{
char ch;
int i=0;
while ((ch!=10)&&(i!=13)) // ch=10 is "return"
{
ch=(char)getchar(); //input will not be hidden
numPass[i++]=ch;
}
numPass[--i]=' '; //need to form a `string`
};
void passFunc()
{
char pass[13];
cout<<"Enter password :- ";
enterPass(pass);
if(strcmp(pass,"myworld")==0)
{
cout<<"Correct Passwordn";
}
else
{
cout<<"n|"<<pass<<"|n";
cout<<"Wrong Passwordn";
exit(0);
}
};
int main()
{
passFunc();
return 0;
}
他们投票否决了你的问题,因为很可能有很多代码在做类似的事情。您可能想从这个问题开始,然后沿着"可能重复"列表进行挖掘。
int verify_password()
{
char u_name[10];
char u_pwd[10];
int x=1;
cout<<"nn Enter user name : ";
cin>>u_name;
cout<<"nn Enter Password : ";
for(int i=0;i<=10;++i)
{
u_pwd[i]=getch();
cout<<"*";
if(u_pwd[i]==13)
{
u_pwd[i]=' ';
break;
}
}
x=strcmp(admin.user_name,u_name);
if (x==0)
{
x=strcmp(admin.password,u_pwd);
}
if(x==0)
cout<<"correct";
else
cout<<"wrong";
}
相关文章:
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 将重载的成员函数传递给函数模板
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- 具有常量引用参数的函数模板专用化
- std::span<const T> 作为函数模板中的参数
- 如何编写一个完美的缩写函数模板?
- 仅在函数模板中为那些定义了函数的类型执行函数
- 如何在C++中伪造虚拟可变参数函数模板?
- 以下代码中的函数模板有什么问题?
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- 将显式实例化的函数模板与转换匹配
- 使用定义函数模板别名
- 函数模板返回类型
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- C++ std::functional 中的可变参数函数模板
- 单行函数模板 c++ 的内联性保证
- C++函数模板需要 &for 数组参数
- 概念解析为使用 std::make_signed_t 时意外的函数模板
- 编程密码函数模板