用VB编写“密码校验”程序的设计

用VB编写“密码校验”程序的设计,第1张

完整代码春档余如下,初始化都已经扒滚做好啦,添加控件试试吧:

Dim NCount As Integer

Private Sub Form_Load()

'初始化控件信息

Caption = "密码校验"

Label1.Caption = "请输入密码:"

Text1.Text = ""

Label2.ForeColor = &HFF&

Label2.Alignment = 2

Label2.FontName = "宋体"

Label2.FontSize = 15.75

Label2.AutoSize = True

Label2.Visible = False

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If Len(Text1.Text) >6 And KeyAscii <>8 And KeyAscii <>13 Then

KeyAscii = 0

End If

If KeyAscii = 13 And Text1.Text = "1234567" Then

Label2.Caption = "欢迎光临!"蠢搏

Label2.Visible = True

ElseIf KeyAscii = 13 Then

If NCount <>1 Then

Label2.Visible = True

Label2.Caption = "密码不符,请再输入一遍!"

Text1.Text = ""

NCount = NCount + 1

Else

Label2.Visible = True

Label2.Caption = "非法用户,请推出程序!"

Text1.Text = ""

Text1.Enabled = False

End If

End If

End Sub

先设计好界面,(如:用标签控件,2个文本框,)在1个要输密码文本框的属性名称中输入password,在要输入名称的文本框简哗的属性名称中输入username.在设手模置字体 想要输入错误密码三次退出程序方法如下; 在密码的代码框中输拦薯行入:unload.me chick=3. End sub

#include <iostream>

#include <string>

using namespace std

const int number=3

const string id[number]={"a","b","c"}

const string passwd[number]={"111","222","333"}

int main()

{

    string m,n

    int i

    cin >>m

    for(i=0 i < number i ++)

        if(id[i] == m) break

    if(i == number) 

    {

        cout<< "用户不存在\n"

    }

    升埋和else

    {

        cin >>n

        if(passwd[i] == n)

            cout<<"欢迎!\n"

        else cout<<"密码错误\n"

    }

    return 0

}

以上为基液枝础功能. 

扩展如下:

#include <iostream>

#include <string>

using namespace std

const int number=3

const string id[number]={"a","b","c"}

const string passwd[number]={"111","222","333"}

int main()

{

    string m,n

    int i,times

    for(times=0 times<3times++)

    {

        cin >>m

        for(i=0 i < number i ++)

            if(id[i] == m) break

  吵盯      if(i == number) 

        {

            cout<< "请重新输入.\n"

        }

        else break

    }

    if(times == 3) 

        cout << "用户不存在\n"

    else

    {

        for(times=0 times<3times++)

        {

            cin >>n

            if(passwd[i] == n)

            {

                cout<<"欢迎!\n"

                break

            }

            else cout<<"请重新输入.\n"

        }

        if(times==3) cout<<"密码错误\n"

    }

    

    return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12364395.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-23
下一篇2023-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存