Skip to content

Commit

Permalink
security
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Jun 17, 2019
1 parent 910a806 commit eac7f9f
Show file tree
Hide file tree
Showing 28 changed files with 1,542 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Csharp/MD5_test/MD5_test.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MD5_test", "MD5_test\MD5_test.csproj", "{CF581D61-F819-4B98-9CCF-2F7EF7BE19FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CF581D61-F819-4B98-9CCF-2F7EF7BE19FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF581D61-F819-4B98-9CCF-2F7EF7BE19FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF581D61-F819-4B98-9CCF-2F7EF7BE19FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF581D61-F819-4B98-9CCF-2F7EF7BE19FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6ECF26E-2F67-406F-8BFF-E338A527053C}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Csharp/MD5_test/MD5_test/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
238 changes: 238 additions & 0 deletions Csharp/MD5_test/MD5_test/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions Csharp/MD5_test/MD5_test/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MD5_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string username; //取出账号
string password; //取出密码
private void Button1_Click(object sender, EventArgs e)
{
username = textBox1.Text.Trim(); //取出账号
password = textBox2.Text.Trim(); //取出密码

//string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //读取连接字符串
string myConnString = "Data Source=.;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=sql";
SqlConnection sqlConnection = new SqlConnection(myConnString); //实例化连接对象
sqlConnection.Open();
password = EncryptWithMD5(password);
string insertStr = "INSERT INTO usertable32 (userid,password) " + "VALUES ('" + username + "','" + password + "')";
SqlCommand cmd = new SqlCommand(insertStr, sqlConnection);
cmd.ExecuteNonQuery();
sqlConnection.Close();
MessageBox.Show("成功写入");
}

private void Button2_Click(object sender, EventArgs e)
{
string myConnString = "Data Source=.;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=sql";
username = textBox1.Text.Trim(); //取出账号
SqlConnection sqlConnection = new SqlConnection(myConnString); //实例化连接对象
sqlConnection.Open();
string sql = "select userid,password from usertable32 where userid = '" + username + "'";
SqlCommand com = new SqlCommand(sql, sqlConnection);
SqlDataReader read = com.ExecuteReader();
while (read.Read())
{
string myUsername = read["userid"].ToString();
string myPassword = read["password"].ToString();
textBox3.Text = myUsername;
textBox4.Text = myPassword;
}
sqlConnection.Close();
MessageBox.Show("成功读取");
}


public static string EncryptWithMD5(string source)
{
byte[] sor = Encoding.UTF8.GetBytes(source);
MD5 md5 = MD5.Create();
byte[] result = md5.ComputeHash(sor);
StringBuilder strbul = new StringBuilder(40);
for (int i = 0; i < result.Length; i++)
{
strbul.Append(result[i].ToString("x2"));//加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位
}
return strbul.ToString();
}


}
}
Loading

0 comments on commit eac7f9f

Please sign in to comment.