SoFunction
Updated on 2025-03-06

C# Method to Encrypt User Passwords using Pseudo-Random Numbers

C# Method to Encrypt User Passwords using Pseudo-Random Numbers

Updated: July 26, 2014 09:50:11 Submission: shichen2014
This article mainly introduces the method of C# using pseudo-random numbers to encrypt user passwords. It has certain reference value for developing C# member system or program security issues. Friends who need it can refer to it.

The examples described in this article are to encrypt user passwords using pseudo-random numbers. This code is the main code of the core part and needs to be implemented in conjunction with other programs. Interested readers can further improve it themselves, without any trouble. The main codes are listed below:

using System; 
using ; 
using ; 
using ; 
using ; 
using ; 
using ; 
using ; 
namespace PRanDataEncrypt 
{ 
public partial class Form1 : Form 
{ 
public Form1() 
{ 
InitializeComponent(); 
} 
private void button1_Click(object sender, EventArgs e) 
{ 
if ( != "") 
{ 
if (DecryptPwd() == ) 
("User login successfully!", "hint", , ); 
else 
("User password is wrong!", "mistake", , ); 
} 
} 

private void button2_Click(object sender, EventArgs e) 
{ 
 =  =  = ; 
(); 
} 

private void textBox2_TextChanged(object sender, EventArgs e) 
{ 
 = EncryptPwd(); 
} 

//Define the pseudo-random number used to encrypt user passwordprivate string randStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; 
#region Encrypt user login password using pseudo-random number/// <summary> 
/// Encrypt user login password using pseudo-random number/// </summary> 
/// <param name="str">User login password</param>/// <returns>Encrypted user login password</returns>private string EncryptPwd(string str) 
{ 
byte[] btData = (str); 
int j, k, m; 
int len = ; 
StringBuilder sb = new StringBuilder(); 
Random rand = new Random(); 
for (int i = 0; i &lt; ; i++) 
{ 
j = (byte)(6); 
btData[i] = (byte)((int)btData[i] ^ j); 
k = (int)btData[i] % len; 
m = (int)btData[i] / len; 
m = m * 8 + j; 
((k, 1) + (m, 1)); 
} 
return (); 
} 
#endregion 
#region Decrypt user login password/// &lt;summary&gt; 
/// Decrypt the user login password/// &lt;/summary&gt; 
/// <param name="str">Encrypted user login password</param>/// <returns>Decrypted user login password</returns>private string DecryptPwd(string str) 
{ 
try 
{ 
int j, k, m, n = 0; 
int len = ; 
byte[] btData = new byte[ / 2]; 
for (int i = 0; i &lt; ; i += 2) 
{ 
k = (str[i]); 
m = (str[i + 1]); 
j = m / 8; 
m = m - j * 8; 
btData[n] = (byte)(j * len + k); 
btData[n] = (byte)((int)btData[n] ^ m); 
n++; 
} 
return (btData); 
} 
catch { return ""; } 
} 
#endregion 
} 
}
  • C#
  • Pseudo-random number
  • encryption
  • password

Related Articles

  • C# method to call Oracle stored procedures

    This article mainly introduces the method of C# calling Oracle stored procedures, including the database and C# corresponding call code, which has certain reference value. Friends who need it can refer to it.
    2015-01-01
  • Five ways to implement string formatting in C#

    C# string formatting is a process of inserting data into a predefined text template to create a new string. It allows developers to more conveniently control the layout and display style of the output content. This article introduces five ways to implement string formatting in C#. The article explains it in detail through code examples. Friends who need it can refer to it.
    2024-07-07
  • Tutorial on the use of a simple and practical framework of Socket in C# .NET

    Recently, a project has to use Socket transmission problem, so I decided to learn it and summarize and share the content I learned. The following article mainly introduces relevant information about the use of the simple and practical Socket framework in C# .NET. The article introduces the example code in this article very detailed. Friends who need it can refer to it.
    2017-09-09
  • C# method to implement treeview binding

    This article mainly introduces the methods of C# to implement treeview binding, including datatable acquisition and node operation, which has certain reference value. Friends who need it can refer to it
    2014-12-12
  • C# method of decoding base64 encoding binary data

    This article mainly introduces the method of decoding base64 in C# to encode binary data, involving the static method of Convert class in C# Convert.FromBase64String usage techniques. Friends who need it can refer to it
    2015-04-04
  • c# Use threads to send and receive data on serialPort (four types)

    This article mainly introduces the use of c# threads to send and receive data on serialPort. The example code is introduced in this article in detail, which has certain reference learning value for everyone's learning or work. Friends who need it, please learn with the editor below.
    2022-07-07
  • Microsoft Expression Web Simplified Chinese Official Version Official Download Address

    Microsoft Expression Web Simplified Chinese Official Version Official Download Address...
    2007-07-07
  • C# Static Variables and Instance Variables Instance Analysis

    This article mainly introduces C# static variables and instance variables, which are important concepts that must be mastered in PHP programming. Friends who need it can refer to it
    2014-09-09
  • Intermodulation operation of C# and Lua code under ToLua framework

    This article mainly introduces the intermodulation operation of C# and Lua code under the ToLua framework, which has good reference value and hopes to be helpful to everyone. Let's take a look with the editor
    2020-11-11
  • Introduction to common features in C# network programming

    This article introduces common features in C# network programming, and the article introduces it in detail through sample code. It has certain reference value for everyone's study or work. Friends who need it can refer to it.
    2022-02-02

Latest Comments