private void Login(string input_username, string input_passwd) { Console.WriteLine("username is " + input_username + " ,password is " + input_passwd); Console.WriteLine("remember is " + remember_username.ToString()); Console.WriteLine("auto is " + auto_login.ToString()); string crypted_passwd = MD5Tools.GetMD5(input_passwd); int port = int.Parse(ConfigurationManager.AppSettings["network_port"]); string ip = ConfigurationManager.AppSettings["network_ip"]; if (!NetworkClient.GetIsConnected()) { NetworkClient.StartNetwork(ip, port); } NetworkClient.network.LoginRequest(input_username, crypted_passwd); while (ClientInfo.login_state != ClientInfo.LoginState.login_success) { if (ClientInfo.login_state == ClientInfo.LoginState.log_error) { MessageBox.Show("登录错误,请检查用户名、密码是否正确!"); ClientInfo.login_state = ClientInfo.LoginState.not_logged_in; Dispatcher.BeginInvoke(new Action(() => { LoadGrid.Visibility = Visibility.Collapsed; login_timer.last_req_time = 0; login_timer.timer.Stop(); })); return; } Thread.Sleep(10); } ClientInfo.self_user.userState = User.user_state.free; ClientInfo.self_user.username = input_username; Dispatcher.BeginInvoke(new Action(() => { ClientInfo.hall = new HallWindow(); ClientInfo.hall.Show(); login_timer.last_req_time = 0; login_timer.timer.Stop(); Close(); LoadGrid.Visibility = Visibility.Collapsed; })); }
public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters) { User user = ParameterTool.GetParameter <User>(request.Parameters, ParameterCode.User); User userDB = manager.GetUserByUsername(user.Username); if (userDB != null) { response.ReturnCode = (short)ReturnCode.Fall; response.DebugMessage = "用户名重复"; } else { user.Password = MD5Tools.GetMD5(user.Password); response.ReturnCode = (short)ReturnCode.Success; manager.AddUser(user); } }
public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters) { Dictionary <byte, object> parameters = request.Parameters; object userObj = null; parameters.TryGetValue((byte)ParameterCode.User, out userObj); User user = JsonMapper.ToObject <User>(userObj.ToString()); //由名字得到数据库中的user对象 User userDB = manager.GetUserByUsername(user.Username); //数据库中存在对象,并且密码输入正确 if (userDB != null && userDB.Password == MD5Tools.GetMD5(user.Password)) { //登录取得成功 response.ReturnCode = (short)ReturnCode.Success; peer.LoginUser = userDB; } else { response.ReturnCode = (short)ReturnCode.Fall; response.DebugMessage = "用户名或密码错误"; } }
public string SyncFiles() { //添加或更新文件 int errorCount = 0; int insertCount = 0; int updateCount = 0; List <FileInfo> ls = new List <FileInfo>(); ls = GetAllDirectoriesFiles(); //ls = FilterSupportedFiles(ls); SqliteHelper sqlHelper = new SqliteHelper(); //保存最新的所有文件 sqlHelper.ExecuteNonQuery($"delete from LatestFiles"); foreach (var f in ls) { try { if (f.FullName.Contains("'") == false) { string fileMD5 = MD5Tools.GetMD5(f.FullName); sqlHelper.ExecuteNonQuery($"insert into LatestFiles(md5,fullname) values('{fileMD5}','{f.FullName}')"); } } catch { errorCount += 1; } } //删除过期的文件 sqlHelper.ExecuteNonQuery($"delete from files where md5 not in (select md5 from LatestFiles)"); foreach (var f in ls) { try { //排除含有'符号的文件,否则插入数据库会出错 if (f.FullName.Contains("'") == false || f.FullName.Contains("~") == false) { string fileMD5 = MD5Tools.GetMD5(f.FullName); string fileModifiedtime = f.LastWriteTime.ToString(); //如果数据库中不存在,直接添加 if (sqlHelper.ExecuteScalar($"select count(MD5) from Files where MD5='{fileMD5}'") != 1) { sqlHelper.ExecuteNonQuery($"insert into Files(MD5,fullname,modifiedtime,gettime) values('{fileMD5}','{f.FullName}','{fileModifiedtime}','{DateTime.Now}')"); insertCount = insertCount + 1; } else { //如果数据库中存在,但是修改日期不一样,先删除,后添加 if (sqlHelper.ExecuteScalar($"select count(MD5) from Files where MD5='{fileMD5}' and modifiedtime<>'{fileModifiedtime}'") == 1) { sqlHelper.ExecuteNonQuery($"delete from Files where MD5='{fileMD5}'"); sqlHelper.ExecuteNonQuery($"insert into Files(MD5,fullname,modifiedtime,gettime) values('{fileMD5}','{f.FullName}','{fileModifiedtime}','{DateTime.Now}')"); updateCount = updateCount + 1; } } } } catch { errorCount = errorCount + 1; } } int total = sqlHelper.ExecuteScalar("select count(*) from files"); return("索引文件共计:" + total.ToString() + ",新增:" + insertCount.ToString() + ",更新:" + updateCount.ToString() + ",错误:" + errorCount.ToString()); }