Click here to Skip to main content
Rate this: bad
good
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:";
   cin>>password;
   cout << "Enter the number of times the password needs to be displayed (1-3)"<<endl;
   cin>>num;
    return 0;
}</iostream>
Posted 2-Dec-12 16:17pm
Edited 2-Dec-12 16:40pm
v4
Comments
Sergey Alexandrovich Kryukov at 2-Dec-12 22:56pm
   
This is not a question. You should do your homework by yourself.
--SA
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.
--SA
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.
--SA
Rate this: bad
good
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:
http://en.wikipedia.org/wiki/Cryptographic_hash_function[^],
http://en.wikipedia.org/wiki/Computational_complexity_theory#Intractability[^].
 
Don't use MD5 or SHA-1 — they are found to be broken; better use one from the SHA-2 family:
http://en.wikipedia.org/wiki/MD5[^],
http://en.wikipedia.org/wiki/SHA-1[^],
http://en.wikipedia.org/wiki/SHA-2[^].
 
Please see my past answers:
storing password value int sql server with secure way[^],
Decryption of Encrypted Password[^].
 
—SA
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 2-Dec-12 23:20pm
   
Thank you very much for your nice words.
--SA
Sergey Alexandrovich Kryukov at 3-Dec-12 5:31am
   
No problem with your reputation. Please see:
http://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspx
The site is to be fixed...
--SA
Rate this: bad
good
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 )
    {
        cin>>nReadPassword;
        if( nReadPassword != nPassword )
        {
            cout<< "Sorry!!incorrect password"<<endl;
            if( nEnterChance == 2 )
            {
                cout<<"You are cross the limit"<<endl;
            }
        }
        else
        {
            cout<<" Success!! you are welcome"<<endl;
            break;
        }
        ++nEnterChance;
    }
    return 1;
}
iam not tested this. also i agree sergey comments. you can refer for this for your homework.
  Permalink  
v2
Comments
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)



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