public override void RunImpl() { CipherParameters key = _client.RsaPair._privateKey; RSAEngine rsa = new RSAEngine(); rsa.init(false, key); byte[] decrypt = rsa.processBlock(Raw, 0, 128); if (decrypt.Length < 128) { byte[] temp = new byte[128]; Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length); decrypt = temp; } string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty); string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty); AccountModel account = AccountService.GetAccountByLogin(username); if (account == null) { if (Config.Config.Instance.ServerConfig.AutoCreate) { account = AccountService.CreateAccount(username, L2Security.HashPassword(password)); } else { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } } else { if (!AccountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password))) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } if (ServerThreadPool.Instance.LoggedAlready(username.ToLower())) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse)); _client.Close(); return; } } Random rnd = new Random(); _client.ActiveAccount = account; _client.SetLoginPair(rnd.Next(), rnd.Next()); _client.SetPlayPair(rnd.Next(), rnd.Next()); _client.Send(LoginOk.ToPacket(_client)); }
public async Task <AccountContract> CreateAccount(string login, string password) { AccountContract acc = new AccountContract { Login = login, Password = L2Security.HashPassword(password) }; acc.AccountId = (int)await _accountCrudRepository.Add(acc); return(acc); }
public override void run() { string username, password; CipherParameters key = getClient().RsaPair._privateKey; RSAEngine rsa = new RSAEngine(); rsa.init(false, key); byte[] decrypt = rsa.processBlock(_raw, 0, 128); if (decrypt.Length < 128) { byte[] temp = new byte[128]; Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length); decrypt = temp; } username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", ""); password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", ""); AccountModel account = accountService.GetAccountByLogin(username); if (account == null) { if (Cfg.AUTO_ACCOUNTS) { account = accountService.CreateAccount(username, L2Security.HashPassword(password)); } else { getClient().sendPacket(new LoginFail(getClient(), LoginFail.LoginFailReason.REASON_USER_OR_PASS_WRONG)); getClient().close(); return; } } else { if (!accountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password))) { getClient().sendPacket(new LoginFail(getClient(), LoginFail.LoginFailReason.REASON_USER_OR_PASS_WRONG)); getClient().close(); return; } if (ServerThreadPool.getInstance().LoggedAlready(username.ToLower())) { getClient().sendPacket(new LoginFail(getClient(), LoginFail.LoginFailReason.REASON_ACCOUNT_IN_USE)); getClient().close(); return; } } Random rnd = new Random(); getClient().activeAccount = account; getClient().setLoginPair(rnd.Next(), rnd.Next()); getClient().setPlayPair(rnd.Next(), rnd.Next()); getClient().sendPacket(new LoginOk(getClient())); }
public async Task <bool> CheckIfAccountIsCorrect(string login, string password) { AccountContract account = await GetAccountByLogin(login); return(account != null && account.Password.SequenceEqual(L2Security.HashPassword(password))); }
public override void RunImpl() { if (_client.State != LoginClientState.AuthedGG) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } var key = _client.RsaPair._privateKey; RSAEngine rsa = new RSAEngine(); rsa.init(false, key); byte[] decrypt = rsa.processBlock(Raw, 0, 128); if (decrypt.Length < 128) { byte[] temp = new byte[128]; Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length); decrypt = temp; } string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty); string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty); AccountContract account = _accountService.GetAccountByLogin(username); if (account == null) { if (_config.ServerConfig.AutoCreate) { account = _accountService.CreateAccount(username, L2Security.HashPassword(password)); } else { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } } else { if (!_accountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password))) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } if (LoginServer.ServiceProvider.GetService <ServerThreadPool>().LoggedAlready(username.ToLower())) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse)); _client.Close(); return; } } _client.ActiveAccount = account; _client.State = LoginClientState.AuthedLogin; _client.Send(LoginOk.ToPacket(_client)); }