-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David
committed
Jun 17, 2019
1 parent
910a806
commit eac7f9f
Showing
28 changed files
with
1,542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.