帮助登录authen [英] help with login authen

查看:82
本文介绍了帮助登录authen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序只允许userdatabase.txt中的userdata在要求登录和密码时输入。但现在我无论如何也可以登录。

谁能告诉我问题在哪里。



my program only allow userdata from "userdatabase.txt" to enter when ask for login and password. but now I anyhow type also can login.
can anyone tell me where is the problem.

void authUser()        // Function that prompts for user to login and matches input with userdatabase.txt
{
    string accountID = "";        // initialize temp accountID to null
    string password = "";        // initialize temp password to null
    int invalidCount = 0;

    char c = ' ';

    bool validUser = false;
    bool failedLogin = false;

    while (validUser != true) // to check for invalid login
    {
        system("clear");
        using std :: cout;
        using std :: endl;
        void Encrypt( char [ ] ); // prototypes of functions used in the code
        void Decrypt( char * ePtr );

        cout << logo_MainMenu << endl;
        if (failedLogin == true)                // Displays error before asking for username/password
        {
            if (invalidCount == 1)              // tests for invalid login, 1 / 3 chance used up
            {
                cout << "\E[1;32mInvalid Account ID / Password. Please try again!\E[0m" << endl;
                cout << "You have used up 1 / 3 chances to login." << endl;
                cout << "If you fail to login after 3 tries, the application will lock down and exit!" << endl;
            }
            else if (invalidCount == 2)         // tests for invalid login, 2 / 3 chance used up
            {
                cout << "\E[1;32mInvalid Account ID / Password. Please try again!\E[0m" << endl;
                cout << "You have used up 2 / 3 chances to login." << endl;
                cout << "If you fail to login after 3 tries, the application will lock down and exit!" << endl;
            }
            else                                // tests for invalid login, 3 / 3 chance used up
            {
                cout << "\E[1;32mInvalid Account ID / Password.\E[0m" << endl;
                cout << "You have used up 3 / 3 chances to login." << endl << endl;
                cout << "The application will now lock down and exit!" << endl;
                exit (0);                       // exit application
            }
        }
        cout << endl << "To login, please enter your Account ID and Password" << endl;
        cout << "(type \"exit\" to terminate the application)" << endl << endl;
        cout << "Account ID: ";
        getline (cin, accountID);

        if (accountID == "exit")                // user can exit anytime
            exit (0);
        // by typing "exit" at username or password
        if (password == "exit")
            exit (0);

        char clear[200] = {0};
        char cipher[200] = {0};  // trying to to encrypting and decrypt 
        char filename[80];
        int x,i;
        ofstream outputFile;
        outputFile.open("yxy.txt"); // the text file that my encrypted password goes into

        ifstream userDatabaseIN("userdatabase.txt", ios::in); // the text file that userdata is stored at

        cout << "Enter Password:" ;   // asking for password
        cin.getline(clear,sizeof(clear));

        x = strlen(clear);
        // Encryption
        for(i=0; i<=x-1; i++)
        {
            if (isspace(clear[i]))
            {
                cipher[i] = clear[i];
            }
            {
                cipher[i] = clear[i]+3;
            }
        }

        // Decryption
        for(i=0; i<=x-1; i++)
        {
            if (isspace(cipher[i]))
            {
                clear[i] = cipher[i];
            }
            else
            {
                clear[i] = cipher[i]-3;
            }
        }


        outputFile<<" Encrypted:" << cipher << endl;
        outputFile<<" Decrypted:" << clear << endl;    //output 
        cout<<"Encrypted and Decrypted password transfer to yxy.txt\n"; 


        return ;
    }

推荐答案

嗯,根据您的代码,您输入的所有内容都将被传递。

起初,这是错误的。

Well, according to your code, everything what you've entered will be passed.
At first, this is wrong.
while (validUser != true)



在你的代码中,没有声明设置validUser = true所以当你一次输入密码和用户ID时它总是会爆发。



其次,没有匹配的声明和反映匹配结果为failedLogin变量。

您只读取密码并对其进行加密,但没有匹配的语句,因此它的反射结果failedLogin不再可用。



这是我的意见。


In your code, there is no statement to set validUser = true so it always break out when you input password and userid at once.

Second, there is no matching statement and reflect matching result to failedLogin variable.
You only read password and encrypt it, but there is no matching statement so it's reflection result failedLogin is no longer usable.

It's my opinion.


这篇关于帮助登录authen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆