Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ Homework
#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 17:17pm
Edited 2-Dec-12 17:40pm
Sergey Alexandrovich Kryukov at 2-Dec-12 22:56pm
This is not a question. You should do your homework by yourself.
Sergey Alexandrovich Kryukov at 2-Dec-12 23:08pm
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.
Sergey Alexandrovich Kryukov at 2-Dec-12 23:10pm
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[^].
Sergey Alexandrovich Kryukov at 2-Dec-12 23:20pm
Thank you very much for your nice words.
Sergey Alexandrovich Kryukov at 3-Dec-12 5:31am
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 at 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
0 OriginalGriff 605
1 Maciej Los 225
2 Abhinav S 171
3 Richard Deeming 160
4 Suvendu Shekhar Giri 159
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,095
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581

Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2015
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