public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer) { User userClient = ParameterTool.GetParameter <User>(request.Parameters, ParameterCode.Register); User userServer = manager.GetUserByUsername(userClient.Username); if (userServer != null) //用户名重复 { response.ReturnCode = (short)ReturnCode.Failure; response.DebugMessage = "用户名重复"; } else //存入数据库 { userClient.Password = Md5Tool.GetMd5(userClient.Password); //md5加密 manager.AddUser(userClient); peer.LoginUser = userClient; response.ReturnCode = (short)ReturnCode.Success; } }
public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer) { User userClient = ParameterTool.GetParameter <User>(request.Parameters, ParameterCode.Login); User userServer = manager.GetUserByUsername(userClient.Username); if (userServer != null && Md5Tool.GetMd5(userClient.Password) == userServer.Password) //登录成功 { //数据库存在用户 //md5加密过后的客户端密码与数据库的密码比较 response.ReturnCode = (short)ReturnCode.Success; peer.LoginUser = userServer; //保存当前用户 } else //登录失败 { response.ReturnCode = (short)ReturnCode.Failure; response.DebugMessage = "用户名或者密码错误"; } }