Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
#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
Updated 2-Dec-12 16:40pm
v4
Comments
Sergey Alexandrovich Kryukov 2-Dec-12 22:56pm    
This is not a question. You should do your homework by yourself.
--SA
Sergey Alexandrovich Kryukov 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 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

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
 
Share this answer
 
Comments
[no name] 2-Dec-12 23:10pm    
You are absolutly correct sergey. I like your way of answering. You are a good teacher also. My vote is 5.
Sergey Alexandrovich Kryukov 2-Dec-12 23:20pm    
Thank you very much for your nice words.
--SA
[no name] 2-Dec-12 23:30pm    
Dear Sergey,
I have a doubt about my reputation. Iam posted answer for two question in codeproject. but i did'nt get any reputation for this. why? actually iam expected 20 points. you are an experienced proffessional. you know why this?
Sergey Alexandrovich Kryukov 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
[no name] 3-Dec-12 5:38am    
Thanks for your reply
Just for your small requirement.
C++
#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.
 
Share this answer
 
v2
Comments
fjdiewornncalwe 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900