编程密码函数模板

programming password function template

本文关键字:函数模板 密码 编程      更新时间:2023-10-16

您好,我正在尝试使用 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";
}