如何将c / c ++中给出的输入转换成***** [英] how to conert input given in c/c++ into *****

查看:71
本文介绍了如何将c / c ++中给出的输入转换成*****的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算用c语言创建一个项目。

i只想知道如何转换***(加密形式)中的用户输入(如密码)并将其与现有密码进行比较。

解决方案

你的标签说C ++,C,Java - 所以我们无法准确回答任何问题:Android的Java解决方案与用于.NET的C ++解决方案或用于控制台应用程序的C解决方案。

但是......



首先,不要加密密码:改为哈希。有关原因的解释如下:密码存储:如何操作。 [ ^ ] - 但是代码是在C#中,所以它可能不是很多用途!根据您的语言/编译器/环境,可以使用类似的功能。



其次,使用****代替密码不加密无论是!所有这一切都是文本框被设置为使用密码字符,因此它不会在屏幕上回显,所以看着你肩膀的家伙可以阅读它! :笑:

你究竟是怎么做的也取决于你尝试工作的语言和环境,所以我们也不能告诉你如何做到这一点!


在C ++中使用Winapi:

当您使用

CreateWindow函数创建用户输入编辑框时,可以使用ES_PASSWORD视觉样式常量。



请看:



http://msdn.microsoft.com/en-us/library/windows/desktop/bb775464(v = vs.85)的.aspx [ ^ ]



这种风格只是输入文字的特殊显示,所以

之后,你可以比较一下使用您的用户密码数据库


#include< iostream>

#incldue< conio.h>



使用nam espace std;



char originalPass [8] = {'1','1','1','1','1','1', '1','1'};

bool condition = true;





int main()

{

char * getPass;

int count = 0;



cout<<输入密码;

while((x = getch())!= 32)

{

cout<< ;*;

getPass [count] = x;

count ++;

}



for(int i = 0; i< count; i ++)>

{

if(originalPass [i]!= getPass [i])

{

条件=假;

休息;

}

}



if(condition == true)

cout<<Password Correct;

else

cout<<密码incorec T;

i am going to create a project on c language.
i just wanna know that how to convert user input(like password) in ***(in encrypted form) and compare it with existing password.

解决方案

Your tags say "C++, C, Java" - so we can't be precise with any answer: a Java solution for Android would be very different from a C++ solution for .NET or a C solution for a console app.
But...

First, don't encrypt passwords: hash them instead. The explanation as to why is here: Password Storage: How to do it.[^] - but teh code is in C#, so it probably isn;t a lot of use to you! Depending on your language / compiler / environment there will be similar functions available though.

Second, the use of "****" instead of the password is not encryption either! All that is it the Textbox being set to use the Password character so it isn't echoed on the screen so teh guy looking over your shoulder can read it! :laugh:
Exactly how you do that will also depend on the language and environment in which you are trying to work, so we can't tell you how to do that either!


In C++ with Winapi:
You can use ES_PASSWORD visual style constant when you create the user input editbox with
CreateWindow function.

Please see this:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb775464(v=vs.85).aspx[^]

This style just a special showing for the inputted text, so
after than, you can compare it with your user-password database


#include<iostream>
#incldue<conio.h>

using namespace std;

char originalPass[8] = {'1','1','1','1','1','1','1','1'};
bool condition = true;


int main()
{
char *getPass;
int count=0;

cout<<"Enter Password";
while((x = getch()) != 32)
{
cout<<"*";
getPass[count] = x;
count++;
}

for(int i = 0;i<count;i++)>
{
if(originalPass[i] != getPass[i])
{
condition = false;
break;
}
}

if (condition==true)
cout<<"Password Correct";
else
cout<<"password incorect";


这篇关于如何将c / c ++中给出的输入转换成*****的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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