使用用户名和密码解密文本文件. [英] Decrypt textfile with username and passwords.

查看:103
本文介绍了使用用户名和密码解密文本文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在制作一个登录表单,将您的用户名和密码保存到一个文本文件(已加密)中,如下所示:

xhsdg495(用户名)-jasjdhfb(密码)

当我尝试解密它时,我收到一条错误消息,提示它无法在Base64中重新协调某些字符.我的问题是:如何删除(space)-(space),以便程序知道用户名和密码是什么?

Hello, I am making a login form that saves your username and password to a text file (encrypted) like this:

xhsdg495 (username) - jasjdhfb (password)

When I try to decrypt it I get an error saying it can''t reconize some characters in the Base64. My question is: How can I remove the (space)-(space) so that the program knows what the username and password is?

推荐答案

事情在这里:
通常,您将使用String.Split,但是不会在字符串上拆分任何重载,因此直接的答案是使用Regex.Split函数:

There are a couple of things here:
Normally, you would use String.Split, but there is no overload which splits on a string, so the direct answer is to use the Regex.Split function:

string myString = "xhsdg495 - jasjdhfb";
string[] parts =  Regex.Split(myString," - ");


部件[0]是"xhsdg495",部件[1]是"jasjdhfb"

但是无论如何,存储加密密码不是一个好习惯:而是存储MD5或(最好是)SHA哈希.由于这些是不可逆的功能,因此您无法从存储的值中找回密码.然后,当他们登录时,您将生成与输入密码相同的哈希值,并比较这两个值.还建议在对用户名进行哈希处理时将其包含在数据中,以防止两个不同用户使用的相同密码生成相同的值.


parts[0] is "xhsdg495" and parts[1] is "jasjdhfb"

But it is not good practice to store encrypted passwords anyway: store a MD5 or (prefereably) SHA hash instead. Since these are non-reversible functions, you cannot get back to the password from the stored value. You then generate the same hash of the entered password when they log in, and compare the two values. It is also recommended that the user name is included in the data when you hash it to prevent the same value being generated by the same password used by two different users.


这篇关于使用用户名和密码解密文本文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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