2012-04-23 50 views
-1

你好,我正在嘗試創建一個密碼功能與c + +處理多達12個字符,並可以調用三個單獨的bool函數: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; 
} 
+0

沒有這是不是從學校我26歲,我試過使用[code]標籤但沒有工作,就像我說的我試圖做一個密碼功能的程序即時編碼將有半敏感信息,爲什麼我的帖子在負面2代表,並沒有什麼,但沒有建設性的意見是這不是一個編碼論壇? – user1350623 2012-04-23 17:30:07

回答

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]='\0'; //need to form a `string` 
}; 


void passFunc() 
{ 
    char pass[13]; 
    cout<<"Enter password :- "; 

    enterPass(pass); 
    if(strcmp(pass,"myworld")==0) 
    { 
    cout<<"Correct Password\n"; 
    } 
    else 
    { 
    cout<<"\n|"<<pass<<"|\n"; 
    cout<<"Wrong Password\n"; 
    exit(0); 
    } 
}; 


int main() 
{ 
    passFunc(); 
    return 0; 
} 

他們是你的問題否決,因爲很可能會有很多代碼做類似的事情。您可能需要從this question開始,並沿着「可能的重複」列表進行挖掘。

0
int verify_password() 
{ 
char u_name[10]; 
char u_pwd[10]; 
int x=1; 
cout<<"\n\n Enter user name : "; 
cin>>u_name; 
cout<<"\n\n Enter Password : "; 
for(int i=0;i<=10;++i) 
{ 
u_pwd[i]=getch(); 
cout<<"*"; 
if(u_pwd[i]==13) 
{ 
u_pwd[i]='\0'; 
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"; 
} 
+0

你可以給你的答案補充一些補充嗎?只有發佈代碼可能會造成混淆。 – 2017-08-23 19:17:56