Click here to Skip to main content
12,951,732 members (65,605 online)
Rate this:
Please Sign up or sign in to vote.
See more:
#include <iostream>
using namespace std;
int main()
   int password = 12345,num;
   cout << " Enter your password:";
   cout << "Enter the number of times the password needs to be displayed (1-3)"<<endl;
    return 0;
Posted 2-Dec-12 16:17pm
Updated 2-Dec-12 16:40pm
This is not a question. You should do your homework by yourself.
I saw your "solution". Thank you for your assessments, but it wasn't necessary. If you have some 20 questions, you have to ask them, and with sufficient detail. And you did not even explain what are your problem, what's wrong do you see in your code, what's not working. Start with my answer... Looks difficult? You see, this is what you need to do for decent password protection. And I don't know ready-to-use C++ implementation of encryption algorithms, but I think you can easily find them. Also, you might ask about some implementation for some concrete OS, I don't know. If so, you would need to specify which exactly.
Next time, please don't put you comments/questions as "Solution". "Submit your solution!" is reserved for cases if you are going to provide some help in response to someone's question. If this is not the case, use "Improve question" or comment on other posts.

I removed your post, because it could bring you only some down-votes or abuse reports.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Please see my comment to the question to understand that you should not expect your work done for you. Also, your school gives you a chance to learn something. Later on, you just might not have enough time to learn all you want, so use this chance well — life is too short.

Some general recommendations:

Passwords are not stored anywhere; this is absolutely not needed for authentication.

Disagree? Feel puzzled? Keep reading.

One of the ways of solving this problem which is usually used is calculation of a cryptographic hash function in both cases and storing the hash. If you want to say that this stored value is just the encrypted password, think again. The big difference is: the cryptographic hash cannot be decrypted at all, this is a one-way function. So, it's infeasible to calculate a password from hash (and, of course, it has nothing to do with system permissions: this is equally infeasible for anyone). And this is not needed: you just store hash and compare hash with hash.

Please see:[^],[^].

Don't use MD5 or SHA-1 — they are found to be broken; better use one from the SHA-2 family:[^],[^],[^].

Please see my past answers:
storing password value int sql server with secure way[^],
Decryption of Encrypted Password[^].

Thank you very much for your nice words.
No problem with your reputation. Please see:
The site is to be fixed...
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Just for your small requirement.
#include <iostream.h>
#include <conio.h>
int main()
    int nPassword = 12345;
    int nEnterChance = 0;
    int nReadPassword;
    cout<<"Enter your password : Note: maximum chance is 3"<<endl;
    while( nEnterChance < 3 )
        if( nReadPassword != nPassword )
            cout<< "Sorry!!incorrect password"<<endl;
            if( nEnterChance == 2 )
                cout<<"You are cross the limit"<<endl;
            cout<<" Success!! you are welcome"<<endl;
    return 1;

iam not tested this. also i agree sergey comments. you can refer for this for your homework.
Marcus Kramer 3-Dec-12 9:53am
Please don't do someone's homework for them. That is not acceptable here at CP. The proper process is to get the OP to do their own work and than ask specific questions where their efforts don't produce results. No one wins when you do someone's homework for them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100