/// <summary> /// 登陆 /// </summary> /// <param name="param"></param> /// <returns></returns> public object Do_UserLogin(BaseApi baseApi) { UserLoginParam userLoginParam = JsonConvert.DeserializeObject <UserLoginParam>(baseApi.param.ToString()); if (userLoginParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } if (userLoginParam.userName == null || userLoginParam.userName == "") { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } if (userLoginParam.password == null || userLoginParam.password == "") { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } string password = MD5Manager.MD5Encrypt32(userLoginParam.password); UserDao userDao = new UserDao(); UserLoginItem userLoginItem = new UserLoginItem(); userLoginItem = userDao.UserLogin(userLoginParam.userName, password); string token = Util.SaveUserMessage(userLoginItem); if (token != "") { userLoginItem.token = token; userLoginItem.isonload = true; return(userLoginItem); } else { throw new ApiException(CodeMessage.ErrorLogin, "ErrorLogin"); } }
public userapp Actualizar(int id, string telephone, string cellphone, string email, string contrasena) { db.Configuration.LazyLoadingEnabled = false; userapp user = db.userapp.Find(id); if (user != null) { user.telephone = telephone; user.cellphone = cellphone; user.email = email; user.passw = MD5Manager.Encrypt(contrasena, true); string pass = MD5Manager.Encrypt(contrasena, true); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(user); } return(null); }
public void submit() { //check each field dbg = "*"; string u = user.text; ok = (u.Length >= 4 && u.Length <= 12); //need to check against special characters tosend = u + "|"; if (!ok) { dbg += "Username length invalid\n"; } u = pass.text; ok = (u.Length >= 6 && u.Length <= 12); //need to check against special characters //hash u(the password) tosend += MD5Manager.hashPassword(u); if (!ok) { dbg += "Password length invalid\n"; tosend = "invalid"; } //Debug.Log(tosend); t.text = dbg; }
static public int UpdatePassWord(string userName, string OldpassWord, string NewPassWord) { if (VerifyLogin(userName, OldpassWord) != 3) { return(0); } MysqlConnector mySql = new MysqlConnector(); mySql.SetServer(AESManager.AESDecrypt(AppVars.dbInfo.ipUrl, AppVars.AppParas.Enc0)); mySql.SetDataBase(AESManager.AESDecrypt(AppVars.dbInfo.dataName, AppVars.AppParas.Enc1)); mySql.SetUserID(AESManager.AESDecrypt(AppVars.dbInfo.userName, AppVars.AppParas.Enc2)); mySql.SetPassword(AESManager.AESDecrypt(AppVars.dbInfo.passWord, AppVars.AppParas.Enc3)); mySql.SetPort(AppVars.dbInfo.portNum.ToString()); mySql.SetCharset("utf-8"); string pwd = NewPassWord, salt = AppVars.AppParas.salt; try { mySql.ExeUpdate(string.Format("update {0} set password = '******' where uid = {2}", "user", MD5Manager.HashString(MD5Manager.HashString(NewPassWord) + salt), AppVars.AppParas.uid)); } catch (Exception ex) { return(0); } AppVars.AppParas.isLogin = false; return(2); }
/// <summary> /// Master server constructor. Initialises child objects, helpers and listeners /// </summary> /// <param name="statusDisplay"></param> /// <param name="commandInterface"></param> private MasterServer(IStatusDisplay statusDisplay, ICommandInterface commandInterface, ICDKeyValidator cdKeyValidator, IGameStatsLog gameStats, ILogWriter logWriter) { if (MasterServer.instance != null) { throw new InvalidOperationException("Attempted to create a Master Server instance whilst another instance was still active"); } // Assign static references MasterServer.instance = this; MasterServer.logWriter = logWriter; // Assign instance references this.statusDisplay = statusDisplay; this.commandInterface = commandInterface; this.cdKeyValidator = cdKeyValidator; this.gameStats = gameStats; // Initialise the command interface if we have one if (commandInterface != null) { commandInterface.OnChange += new EventHandler(DisplayCommandInterface); } // GeoIP resolver is used to resolve IP addresses to locations geoIP = new GeoIP(); // MD5 database is used to download new MD5 package data to connecting servers md5Manager = new MD5Manager(); // IP ban manager used to ban clients from accessing the server banManager = new IPBanManager(); // Create the Server List object serverList = new ServerList(this); // Create the web server webServer = new WebServer(banManager); // Initialise the status display module if we have one if (statusDisplay != null) { logBufferSize = statusDisplay.LogBufferSize; logBufferWrap = statusDisplay.LogBufferWrap; displayTimer = new Timer(new TimerCallback(this.Display)); Display(null); } // Load the GeoIP database, MD5 database and ban list from the files (this happens last because they may take a while) geoIP.Load(MasterServer.Settings.GeoIPDataFile); md5Manager.Load(MasterServer.Settings.MD5DataFile); banManager.Load(MasterServer.Settings.BanListFile); }
public userapp Login(string email, string pass) { db.Configuration.LazyLoadingEnabled = false; pass = MD5Manager.Encrypt(pass, true); List <userapp> user = db.userapp.Where(r => r.email.Equals(email)).Where(r => r.passw.Equals(pass)).ToList(); if (user.Count > 0) { userapp userapp = user.ElementAt(0); return(userapp); } return(null); }
public void sendemail(userapp user, string email) { user.passw = CreatePassword(6); var fromAddress = new MailAddress("*****@*****.**", "Se le tiene"); var toAddress = new MailAddress(user.email, "To Name"); const string fromPassword = "******"; const string subject = "Cambio de contraseña"; string body = "<h3>Cordial saludo</h3><h3 style=\"text-align: justify;\">Tu nueva contraseña es " + user.passw + "</p>"; user.passw = MD5Manager.Encrypt(user.passw, true); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); try { var smtp = new SmtpClient { Host = "72.29.75.91", Port = 25, EnableSsl = false, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Timeout = 10000, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; var message = new MailMessage(fromAddress, toAddress); message.IsBodyHtml = true; message.Subject = subject; message.Body = body; smtp.EnableSsl = false; smtp.Send(message); } catch (Exception e) { Console.WriteLine("Ouch!" + e.ToString()); } }
static public int VerifyLogin(string userName, string passWord) { MysqlConnector mySql = new MysqlConnector(); MySqlDataReader reader; mySql.SetServer(AESManager.AESDecrypt(AppVars.dbInfo.ipUrl, AppVars.AppParas.Enc0)); mySql.SetDataBase(AESManager.AESDecrypt(AppVars.dbInfo.dataName, AppVars.AppParas.Enc1)); mySql.SetUserID(AESManager.AESDecrypt(AppVars.dbInfo.userName, AppVars.AppParas.Enc2)); mySql.SetPassword(AESManager.AESDecrypt(AppVars.dbInfo.passWord, AppVars.AppParas.Enc3)); mySql.SetPort(AppVars.dbInfo.portNum.ToString()); mySql.SetCharset("utf-8"); string pwd = "", salt = AppVars.AppParas.salt; int uid = 0, type = 0; try { reader = mySql.ExeQuery(string.Format("select * from {0} where username = '******'", "user", userName)); while (reader.Read()) { uid = Int32.Parse(reader.GetValue(0).ToString()); pwd = reader.GetValue(1).ToString(); salt = reader.GetValue(2).ToString(); type = Int32.Parse(reader.GetValue(3).ToString()); } } catch (Exception ex) { return(0); } if (pwd == "" || salt == "") { return(1); } if (MD5Manager.HashString(MD5Manager.HashString(passWord) + salt) == pwd) { AppVars.AppParas.isAdmin = type == 0 ? true : false; AppVars.AppParas.isLogin = true; AppVars.AppParas.uid = uid; AppVars.AppParas.UserName = userName; return(2); } return(3); }
public static string SaveUserMessage(UserLoginItem userLoginItem) { string token = ""; if (userLoginItem.userCode != "" && userLoginItem.userCode != null) { token = MD5Manager.createToken(userLoginItem.userCode); using (var client = ConnectionMultiplexer.Connect(Global.Redis)) { TimeSpan timeSpan = new TimeSpan(0, 30, 0); var db = client.GetDatabase(0); db.StringSet(token, userLoginItem.userCode + "," + userLoginItem.shopId + "," + userLoginItem.power, timeSpan); return(token); } } else { return(token); } }
/// <summary> /// Create a new connection instance to handle an inbound connection /// </summary> /// <param name="socket">TCP socket for communicating with the remote server</param> /// <param name="connectionLogWriter">Log writer module</param> /// <param name="serverList">Server List object</param> /// <param name="geoIP">GeoIP resolver</param> /// <param name="md5Manager">MD5 database manager</param> /// <param name="banManager">IP ban manager</param> /// <param name="cdKeyValidator">CD key validator</param> /// <param name="gameStats">Game stats module</param> public Connection(Socket socket, IConnectionLogWriter logWriter, ServerList serverList, GeoIP geoIP, MD5Manager md5Manager, IPBanManager banManager, ICDKeyValidator cdKeyValidator, IGameStatsLog gameStats) : this(socket, logWriter, serverList, geoIP) { // Raise the NewConnection event for connected packet analysers OnNewConnection(); // Check whether the remote host is banned if (banManager.IsBanned((socket.RemoteEndPoint as IPEndPoint).Address)) { ConnectionLog("BANNED"); socket.Close(); return; } this.md5Manager = md5Manager; this.cdKeyValidator = cdKeyValidator; this.gameStats = gameStats; // Handle this connection in a new thread ConnectionThreadManager.CreateStart(new ThreadStart(Handle)); }
/// <summary> /// Shut down this listener and all child threads /// </summary> public void Shutdown() { aborted = true; this.serverList = null; this.geoIP = null; this.cdKeyValidator = null; this.gameStats = null; this.md5Manager = null; this.banManager = null; if (listenThread != null) { // Try to close the listen socket if (listenSocket != null) { try { listenSocket.Close(); } catch { } } // Try to forcibly abort the listen thread listenThread.Abort(); listenThread.Join(); listenThread = null; MasterServer.Log("[NET] Query listener socket {0} shut down.", endpoint.Port); } // Abort active connections ConnectionManager.AbortAll(endpoint.Port); // Release log writer ModuleManager.ReleaseModule <IConnectionLogWriter>(); }
/// <summary> /// Constructor, create a new query listener at the specified endpoint /// </summary> /// <param name="endpoint">Endpoint for this listener</param> /// <param name="serverList">Server list object to pass to new connections</param> /// <param name="geoIP">GeoIP resolver to pass to new connections</param> /// <param name="md5Manager">MD5 manager to pass to new connections</param> /// <param name="banManager">IP ban manager to pass to new connections</param> /// <param name="cdKeyValidator">CD key validator module to pass to new connections</param> /// <param name="gameStats">Game stats module to pass to new connections</param> public QueryListener(IPEndPoint endpoint, ServerList serverList, GeoIP geoIP, MD5Manager md5Manager, IPBanManager banManager, ICDKeyValidator cdKeyValidator, IGameStatsLog gameStats) { // Endpoint to listen this.endpoint = endpoint; // These objects are passed to new connections this.serverList = serverList; this.geoIP = geoIP; this.md5Manager = md5Manager; this.banManager = banManager; this.cdKeyValidator = cdKeyValidator; this.gameStats = gameStats; // Get configured connection log writer module this.logWriter = ModuleManager.GetModule <IConnectionLogWriter>(); // Bind the listen socket ready to begin listening listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); listenSocket.Bind(this.Endpoint); // Create and start the listen thread listenThread = new Thread(ListenThreadProc); listenThread.Start(); }
public async Task <IHttpActionResult> Postuserapp(userapp userapp) { db.Configuration.LazyLoadingEnabled = false; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { List <userapp> user = db.userapp.Where(r => r.email.Equals(userapp.email)).ToList(); if (user.Count > 0) { return(Content(HttpStatusCode.BadRequest, "Usuario existente")); } userapp.passw = MD5Manager.Encrypt(userapp.passw, true); userapp.status = 1; db.userapp.Add(userapp); await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(Ok(userapp)); }
static public int RegNewUser(string userName, string passWord, string Email) { int VerifyExist = VerifyLogin(userName, passWord); if (VerifyExist == 0) { return(0); } else if (VerifyExist != 1) { return(1); } MysqlConnector mySql = new MysqlConnector(); mySql.SetServer(AESManager.AESDecrypt(AppVars.dbInfo.ipUrl, AppVars.AppParas.Enc0)); mySql.SetDataBase(AESManager.AESDecrypt(AppVars.dbInfo.dataName, AppVars.AppParas.Enc1)); mySql.SetUserID(AESManager.AESDecrypt(AppVars.dbInfo.userName, AppVars.AppParas.Enc2)); mySql.SetPassword(AESManager.AESDecrypt(AppVars.dbInfo.passWord, AppVars.AppParas.Enc3)); mySql.SetPort(AppVars.dbInfo.portNum.ToString()); mySql.SetCharset("utf-8"); string pwd = passWord, salt = AppVars.AppParas.salt; try { mySql.ExeUpdate(string.Format("insert into {0}({1},{2},{3}) values('{4}','{5}',{6},'{7}')", "user", "username", "password", "type", userName, MD5Manager.HashString(MD5Manager.HashString(passWord) + salt), 1, Email)); } catch (Exception ex) { return(0); } if (VerifyLogin(userName, passWord) == 3) { return(2); } return(0); }
public void submit() { //hash password tosend = user.text + "|" + MD5Manager.hashPassword(p.text); }
public void SetFromHash(byte[] LongKey) { key = MD5Manager.ComputeHash(LongKey); }
public void SetFromHash(string StringKey) { key = MD5Manager.ComputeHash(Encoding.Default.GetBytes(StringKey)); }
/// <summary> /// Constructor, called by the Connection class when it has established that this connection is to a /// server and has performed the initial authentication handshake. At this point the remote server /// should still be in the waiting for heartbeat State. /// </summary> /// <param name="serverList"></param> /// <param name="socket"></param> /// <param name="banFile"></param> public ServerConnection(Connection parentConnection, Socket socket, IConnectionLogWriter logWriter, ServerList serverList, GeoIP geoip, OperatingSystem operatingSystem, string locale, bool bStatLogging, MD5Manager md5Manager, ICDKeyValidator cdKeyValidator, IGameStatsLog gameStats) : base(socket, logWriter, serverList, geoip) { this.outerConnection = parentConnection; this.operatingSystem = operatingSystem; this.locale = locale; this.md5Manager = md5Manager; this.cdKeyValidator = cdKeyValidator; this.gameStats = gameStats; // Socket ID for logging SocketID = String.Format("{0}:{1}", (socket.RemoteEndPoint as IPEndPoint).Address, (socket.RemoteEndPoint as IPEndPoint).Port); // Set socket timeout socket.ReceiveTimeout = socketTimeoutSeconds * 1000; MasterServer.Log("[{0}] Accepting new server connection. Version={1}", (socket.RemoteEndPoint as IPEndPoint).Address.ToString(), parentConnection.Version); int matchID = serverList.GetMatchID(null); // Create the server object and register it with the server list server = new Server(this, parentConnection.Version, (socket.RemoteEndPoint as IPEndPoint).Address, parentConnection.CDKeyHash, geoip, serverList.GetHeartbeatCode(), bStatLogging, operatingSystem, locale, matchID); serverList.Add(server); }
/// <summary> /// Shut down the master server instance /// </summary> private void Shutdown() { // End listen thread and close the listen sockets EndListening(); // Web server if (webServer != null) { webServer.Dispose(); webServer = null; } // Shut down the server list if (serverList != null) { serverList.Shutdown(); serverList = null; } // Ban manager if (banManager != null) { banManager.Dispose(); banManager = null; } // MD5 database if (md5Manager != null) { md5Manager.Dispose(); md5Manager = null; } // GeoIP resolver if (geoIP != null) { geoIP.Dispose(); geoIP = null; } // Display update timer if (displayTimer != null) { displayTimer.Change(Timeout.Infinite, Timeout.Infinite); displayTimer.Dispose(); displayTimer = null; } // Shut down the status display if we have one if (statusDisplay != null) { statusDisplay.Notify("EXIT"); ModuleManager.ReleaseModule <IStatusDisplay>(); statusDisplay = null; } // Shut down the command interface if we have one if (commandInterface != null) { commandInterface.OnChange -= new EventHandler(DisplayCommandInterface); ModuleManager.ReleaseModule <ICommandInterface>(); commandInterface = null; } }