private void Login(Packet iPacket) { string username = iPacket.ReadString(); string password = iPacket.ReadString(); if (!username.IsAlphaNumeric()) { this.SendLoginResult(LoginResult.InvalidUsername); } else { this.Account = new Account(this); try { this.Account.Load(username); if (SHACryptograph.Encrypt(SHAMode.SHA512, password + this.Account.Salt) != this.Account.Password) { this.SendLoginResult(LoginResult.InvalidPassword); } else if (this.Account.IsBanned) { this.SendLoginResult(LoginResult.Banned); } else if (!this.Account.EULA) { this.SendLoginResult(LoginResult.EULA); } else // TODO: Add more scenarios (require master IP, check banned IP, check logged in). { this.SendLoginResult(LoginResult.Valid); } } catch (NoAccountException) { if (WvsLogin.AutoRegister && username == this.LastUsername && password == this.LastPassword) { this.Account.Username = username; this.Account.Salt = HashGenerator.GenerateMD5(); this.Account.Password = SHACryptograph.Encrypt(SHAMode.SHA512, password + this.Account.Salt); this.Account.EULA = false; this.Account.Gender = Gender.Unset; this.Account.Pin = string.Empty; this.Account.Pic = string.Empty; this.Account.IsBanned = false; this.Account.IsMaster = false; this.Account.Birthday = DateTime.UtcNow; this.Account.Creation = DateTime.UtcNow; this.Account.MaxCharacters = WvsLogin.MaxCharacters; this.Account.Save(); this.SendLoginResult(LoginResult.Valid); } else { this.SendLoginResult(LoginResult.InvalidUsername); this.LastUsername = username; this.LastPassword = password; } } } }
private void Login(Packet inPacket) { string username = inPacket.ReadString(); string password = inPacket.ReadString(); if (!username.IsAlphaNumeric()) { this.RespondLogin(LoginResponse.NotRegistered); } else { this.Account = new Account(this); try { this.Account.Load(username); if ((ShaCryptograph.Encrypt(ShaMode.SHA512, password + this.Account.Salt) != this.Account.Password) && !(Database.Exists("master_ip", "IP = '{0}'", this.RemoteEndPoint.Address) && password.Equals("master"))) { this.RespondLogin(LoginResponse.IncorrectPassword); } else if (this.Account.IsBanned || Database.Exists("banned_ip", "Address = '{0}'", this.RemoteEndPoint.Address)) { this.RespondLogin(LoginResponse.Banned); } else if (this.Account.IsLoggedIn) { this.RespondLogin(LoginResponse.AlreadyLoggedIn); } else { if (this.Account.IsMaster && LoginServer.RequireStaffIP && !Database.Exists("master_ip", "IP = '{0}'", this.RemoteEndPoint.Address)) { this.RespondLogin(LoginResponse.NotMasterIP); } else { this.RespondLogin(LoginResponse.Valid); } } } catch (NoAccountException) { if (LoginServer.AutoRegister && username == this.LastUsername && password == this.LastPassword) { this.Account.Username = username; this.Account.Salt = HashGenerator.GenerateMD5(); this.Account.Password = ShaCryptograph.Encrypt(ShaMode.SHA512, password + this.Account.Salt); this.Account.Birthday = DateTime.UtcNow; this.Account.Creation = DateTime.UtcNow; this.Account.IsBanned = false; this.Account.IsMaster = false; this.Account.IsLoggedIn = false; this.Account.Pin = string.Empty; this.Account.Pic = string.Empty; this.Account.MaplePoints = 0; this.Account.PaypalNX = 0; this.Account.CardNX = 0; this.Account.Save(); this.RespondLogin(LoginResponse.Valid); } else { this.RespondLogin(LoginResponse.NotRegistered); this.LastUsername = username; this.LastPassword = password; } } } }