password authentication logic!

Hi everyone! every time i come up with password authentication logic, later i find a bug in it which would result in access even if login info is wrong(in certain way). just came up with new one. seems right for now. could anyone have a look and see if it is ok. also new logic for password authentication is also welcomed(but please note that i am new,4 days into c++. so please only use concepts of loop, if and boolean operators)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  my current code is:


#include <iostream>
#include <string>
using namespace std;
void password_check();//check function type
int main()
{
    password_check();
    cout<<"Login Successful! Access allowed!"<<endl;
}

void password_check()
{
    string user_name;
    string password;
    do
    {

        cout<<"Enter user name: ";
        cin>>user_name;
        cout<<"Enter password: ";
        cin >> password;

        if (!((user_name=="burger"&&password=="fries")||(user_name=="code"&&password=="blocks")))
        {
            cout<<"Bad user name or password. Try again!"<<endl;
        }

    }while(!((user_name=="burger"&&password=="fries")||(user_name=="code"&&password=="blocks")));
}




for insight into what kind of bug i am talking about, here is one of my buggy code.


1
2
3
4
5
6
7
8
9
do
    {
        <necessary code of prompting username and password>

    }while((user_name!="burger"&&user_name!="code")||(password!="fries"&&password!="blocks"));

see in this code, any user name can be matched with any password. eg.if original login info was combo of username=burger and password=fries,  while entering login info, even the combo of username=burger and password=blocks would give access.



Any help would be highly appreciated!


Topic archived. No new replies allowed.