首页

C# Socket登录验证示例

c#

2021-5-9

C# Socket登录验证

一、说明


本程序只是学习应用Socket登录验证和序列化、反序列化的应用,所以只使用了最基本Socket函数,不是框架。


为了便于学习,服务端使用Access数据库,如需修改数据库内的图片,自建程序文件,写代码:


for (int i=0;i<29;i )


{


  byte[] imagebytes = ReadImageFile(i “.jpg”);


  OleDbCommand com = new OleDbCommand(“UPDATE UserInfo SET User_Portrait=(@ImageList) WHERE id=” (i 1), Conn);


  com.Parameters.Add(“ImageList”, OleDbType.Binary);


  com.Parameters[“ImageList”].Value = imagebytes;


  com.ExecuteNonQuery();


 }


将图片更新到数据库中,本程序中限定图像大小为80*80。


数据结构定义在dataStructure.cs,每条传输数据生成新的验证码,根据验证解密,见每个class中的SecretKey。


总的密钥:


string sKey = “㊣o(╥﹏╥)o”; // 密钥8位


服务端客户端要一致。




二、使用

Client客户端设置服务器地址,可以是本机,Login_Form.cs。


private string ServerAddress = “服务器ip”; // 服务器ip地址


public static int port = 51888; // 使用的端口号


Server服务端与客户端一致,Form1.cs。


private IPAddress[] ServerAddress = Dns.GetHostAddresses(“服务器ip”); // 服务器ip地址


private int port = 51888; // 使用的端口号


编译后先执行Server.exe,再执行Client.exe,


用户名1000至1028,密码为123456


三、使用的组件和修改


界面使用:http://www.haolizi.net/example/view_14426.html 的SQK.DLL


修改了UiScrollBoxMethod.cs,增加了滚动到最底部函数,自行编写:


SetBottom()函数


……


foreach (UiControlsMethod.ADraggableGDIObject item in m_DraggableGDIObjects)


{


   set_y = limtY;


    ……


   item.Region = new Rectangle(0, set_y, item.Region.Width, item.Region.Height);


   ScrollBox_.Invalidate();


}


修改了UiInputBoxMethods.cs,解决了粘贴带文字样式的问题,本程序中没有使用,可以参照本程序INputForm.cs自行修改。

四、Win7、Win8都可运行,建议Win10运行,效果更好,Vs2017编译,2015也可以。


.Net4.6.1,如其他版本,需重新编译http://www.haolizi.net/example/view_14426.html 的SQK.DLL



资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
Client/.vs/Client/v15/.suo , 84992
Client/.vs/Client/v15/Server/sqlite3/db.lock , 0
Client/.vs/Client/v15/Server/sqlite3/storage.ide , 1994752
Client/Client/App.config , 186
Client/Client/appForm.cs , 17066
Client/Client/bin/Debug/Client.exe , 6488576
Client/Client/bin/Debug/Client.exe.config , 186
Client/Client/bin/Debug/Client.pdb , 77312
Client/Client/bin/Debug/fontawesome-webfont.ttf , 165548
Client/Client/bin/Debug/Paintdrp.ttf , 47926
Client/Client/bin/Debug/ResFile/0-min.png , 1089
Client/Client/bin/Debug/ResFile/0.png , 16058
Client/Client/bin/Debug/ResFile/1-min.png , 1118
Client/Client/bin/Debug/ResFile/1.png , 16094
Client/Client/bin/Debug/ResFile/10-min.png , 1094
Client/Client/bin/Debug/ResFile/10.png , 16080
Client/Client/bin/Debug/ResFile/11-min.png , 1140
Client/Client/bin/Debug/ResFile/11.png , 16135
Client/Client/bin/Debug/ResFile/12-min.png , 1129
Client/Client/bin/Debug/ResFile/12.png , 16130
Client/Client/bin/Debug/ResFile/13-min.png , 1090
Client/Client/bin/Debug/ResFile/13.png , 16092
Client/Client/bin/Debug/ResFile/14-min.png , 1156
Client/Client/bin/Debug/ResFile/14.png , 16102
Client/Client/bin/Debug/ResFile/15-min.png , 1077
Client/Client/bin/Debug/ResFile/15.png , 16044
Client/Client/bin/Debug/ResFile/16-min.png , 1162
Client/Client/bin/Debug/ResFile/16.png , 16220
Client/Client/bin/Debug/ResFile/17-min.png , 1111
Client/Client/bin/Debug/ResFile/17.png , 16089
Client/Client/bin/Debug/ResFile/18-min.png , 1133
Client/Client/bin/Debug/ResFile/18.png , 16113
Client/Client/bin/Debug/ResFile/19-min.png , 1049
Client/Client/bin/Debug/ResFile/19.png , 16054
Client/Client/bin/Debug/ResFile/2-min.png , 1079
Client/Client/bin/Debug/ResFile/2.png , 16090
Client/Client/bin/Debug/ResFile/20-min.png , 1099
Client/Client/bin/Debug/ResFile/20.png , 16109
Client/Client/bin/Debug/ResFile/21-min.png , 1125
Client/Client/bin/Debug/ResFile/21.png , 16090
Client/Client/bin/Debug/ResFile/22-min.png , 1119
Client/Client/bin/Debug/ResFile/22.png , 16172
Client/Client/bin/Debug/ResFile/23-min.png , 1149
Client/Client/bin/Debug/ResFile/23.png , 16153
Client/Client/bin/Debug/ResFile/3-min.png , 1162
Client/Client/bin/Debug/ResFile/3.png , 16166
Client/Client/bin/Debug/ResFile/4-min.png , 1173
Client/Client/bin/Debug/ResFile/4.png , 16128
Client/Client/bin/Debug/ResFile/5-min.png , 1085
Client/Client/bin/Debug/ResFile/5.png , 16085
Client/Client/bin/Debug/ResFile/6-min.png , 1039
Client/Client/bin/Debug/ResFile/6.png , 16059
Client/Client/bin/Debug/ResFile/7-min.png , 1103
Client/Client/bin/Debug/ResFile/7.png , 16206
Client/Client/bin/Debug/ResFile/8-min.png , 1157
Client/Client/bin/Debug/ResFile/8.png , 16092
Client/Client/bin/Debug/ResFile/9-min.png , 1156
Client/Client/bin/Debug/ResFile/9.png , 16307
Client/Client/bin/Debug/ResFile/background.jpg , 145381
Client/Client/bin/Debug/ResFile/edit.png , 18482
Client/Client/bin/Debug/ResFile/login_input.png , 17084
Client/Client/bin/Debug/ResFile/logo.gif , 6448863
Client/Client/bin/Debug/ResFile/wait.gif , 765
Client/Client/bin/Debug/SQK_Ui.dll , 633856
Client/Client/Client.csproj , 5325
Client/Client/connectForm.cs , 404
Client/Client/connectForm.Designer.cs , 3483
Client/Client/connectForm.resx , 9679426
Client/Client/dataStructure.cs , 6182
Client/Client/DES.cs , 2572
Client/Client/faceForm.cs , 1415
Client/Client/faceForm.Designer.cs , 1700
Client/Client/faceForm.resx , 5817
Client/Client/INputForm.cs , 4810
Client/Client/INputForm.Designer.cs , 1804
Client/Client/INputForm.resx , 5817
Client/Client/ListForm.cs , 14699
Client/Client/Login_Form.cs , 10897
Client/Client/Login_Form.Designer.cs , 1091
Client/Client/Login_Form.resx , 5817
Client/Client/Program.cs , 437
Client/Client/Properties/AssemblyInfo.cs , 1310
Client/Client/Properties/Resources.Designer.cs , 2853
Client/Client/Properties/Resources.resx , 5612
Client/Client/Properties/Settings.Designer.cs , 1106
Client/Client/Properties/Settings.settings , 249
Client/Client/RichTexExt.cs , 5999
Client/Client/Serializer.cs , 4466
Client/Client.sln , 1117
Server/.vs/Server/v15/.suo , 68096
Server/.vs/Server/v15/Server/sqlite3/db.lock , 0
Server/.vs/Server/v15/Server/sqlite3/storage.ide , 798720
Server/Server/App.config , 189
Server/Server/bin/Debug/Server.exe , 23040
Server/Server/bin/Debug/Server.exe.config , 189
Server/Server/bin/Debug/Server.pdb , 46592
Server/Server/bin/Debug/SQK_Ui.dll , 633856
Server/Server/bin/Debug/UserData.mdb , 1482752
Server/Server/dataStructure.cs , 5887
Server/Server/DES.cs , 2536
Server/Server/DesSG_String.cs , 496
Server/Server/Form1.cs , 9843
Server/Server/Form1.Designer.cs , 3813
Server/Server/Form1.resx , 5817
Server/Server/Program.cs , 518
Server/Server/Properties/AssemblyInfo.cs , 1310
Server/Server/Properties/Resources.Designer.cs , 2825
Server/Server/Properties/Resources.resx , 5612
Server/Server/Properties/Settings.Designer.cs , 1093
Server/Server/Properties/Settings.settings , 249
Server/Server/RichTexExt.cs , 5999
Server/Server/Serializer.cs , 4466
Server/Server/Server.csproj , 4120
Server/Server.sln , 1117
没有账号? 忘记密码?

社交账号快速登录