C++语言密码验证String类和char

 时间:2026-02-13 05:20:00

1、//程序运行状态截图,以及源码。

using namespace std;

#include "iostream"

#include "conio.h"

#include "string"

int cout_password(string password)

{

    cout<<endl<<"测试模块:输入的密码:"<<password<<endl<<endl;

}

int main()

{

    string user_user,password,if_user_password;

    char user_password[0XFF];

    user_user="Administered";

    password="admin";

    cout<<"用户名:"<<user_user<<endl<<"密码:"; 

    for(int sum=0;(user_password[sum]=getch())!='\r';sum++,cout<<"*");

    cout<<endl;

    if_user_password=user_password;

    if(if_user_password.compare(password)==true)

    cout<<"验证状态:成功!"<<endl;

    else

    cout<<"验证状态:失败!"<<endl; 

    cout_password(if_user_password);

    return 0;

C++语言密码验证String类和char

2、string user_user,password,if_user_password;

char user_password[0XFF];

定义string变量的字符串用来对比或者储存。

char变量用于接收键盘输入的数据。

C++语言密码验证String类和char

3、user_user="Administered";

password="admin";

string变量初始化(可以中文)。

C++语言密码验证String类和char

4、 cout<<"字符串"<<endl;

cout输出字符串。

C++语言密码验证String类和char

5、for(int sum=0;(user_password[sum]=getch())!='\r';sum++,cout<<"*");

cout<<endl;

使用char类型接收键盘输入的按键消息。并储存到数组中。每输入一次则输出“*”,结束条件是遇到回车。

cout<<endl;作用输出换行,也是为了美观。

C++语言密码验证String类和char

6、if_user_password=user_password;

user_password(char数组变量)接收到的按键消息转换为if_user_password(sring)变量。

C++语言密码验证String类和char

7、if(if_user_password.compare(password)==true)

cout<<"验证状态:成功!"<<endl;

else

cout<<"验证状态:失败!"<<endl; 

将if_user_password和password的string变量做字符串对比。字符串全部一致执行cout<<"验证状态:成功!"<<endl;语句,不一致执行cout<<"验证状态:失败!"<<endl; 语句。

C++语言密码验证String类和char

8、cout_password(if_user_password);、

调用int cout_password(if_user_password);模块,作为测试模块使用。主要验证程序的完整性,有没有BUG或者不是我们想要的运行状态。

C++语言密码验证String类和char

  • 用javascript制作网页背景色渐变特效
  • 城通网盘怎么下载城通网盘的资源
  • 怎么使用lol换肤魔盒
  • 如何锻炼自己的爆发力
  • 尿黄的原因是什么 小便发黄是怎么回事
  • 热门搜索
    浙江千岛湖旅游攻略 游多多旅游网 甘南旅游景点大全 湖北在线旅游网 加尔各答旅游 丽江旅游介绍 宁波旅游地图 三月份去哪里旅游好 我要旅游网 济南好玩的旅游景点