请论坛编写程序以获取用户的密码。从内部密码“12345”检查用户的密码。如果密码正确,请显示“欢迎您!”否则...... [英] Please Forum Write a program to get a password from the user. Check the user’s password from the internal password that is ‘12345’. If the password is correct, display “you are welcome!” Else...

查看:99
本文介绍了请论坛编写程序以获取用户的密码。从内部密码“12345”检查用户的密码。如果密码正确,请显示“欢迎您!”否则......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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>

推荐答案

请查看我对该问题的评论,了解您不应该期待您的工作为你做了。此外,您的学校让您有机会学习一些东西。后来,你可能没有足够的时间学习所有你想要的东西,所以要好好利用这个机会 - 生命太短暂。



一些一般建议:



密码不会存储在任何地方;这绝对不需要身份验证。



不同意?感到疑惑?继续阅读。



通常使用的解决此问题的方法之一是在两种情况下计算加密哈希函数并存储哈希。如果您想说这个存储的值只是加密密码,请再想一想。最大的区别是:加密哈希根本无法解密,这是一个单向函数。因此,从哈希计算密码是不可行的(当然,它与系统权限无关:这对任何人来说都是不可行的)。这不是必需的:你只需存储哈希值并将哈希值与哈希值进行比较。



请参阅:

http://en.wikipedia.org/wiki/Cryptographic_hash_function [ ^ ],

http ://en.wikipedia.org/wiki/Computational_complexity_theory#Intractability [ ^ ]。



不要使用MD5或SHA-1 - 它们被发现被打破;更好地使用SHA-2系列中的一个:

http://en.wikipedia.org/wiki/ MD5 [ ^ ],

http://en.wikipedia.org/wiki/SHA-1 [ ^ ],

http://en.wikipedia.org/wiki/SHA-2 [ ^ ]。



请查看我过去的答案:

存储密码值int sql server with secure方式 [ ^ ],

加密密码的解密 [ ^ ]。



-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


只是为了你的小要求。

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;
}



我没有测试过这个。我同意sergey评论。你可以参考你的作业。


iam not tested this. also i agree sergey comments. you can refer for this for your homework.


这篇关于请论坛编写程序以获取用户的密码。从内部密码“12345”检查用户的密码。如果密码正确,请显示“欢迎您!”否则......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆