且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用用户名和密码解密文本文件.

更新时间:2022-05-31 21:40:28

事情在这里:
通常,您将使用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.