async def get_login(self, name: str, phash: str) -> Optional[Player]: # Only used cached results - the user should have # logged into bancho at least once. (This does not # mean they're logged in now). # Let them pass as a string for ease of access phash = phash.encode() bcrypt_cache = glob.cache['bcrypt'] if phash not in bcrypt_cache: # User has not logged in through bancho. return res = await glob.db.fetch( 'SELECT pw_hash FROM users WHERE name_safe = %s', [Player.ensure_safe(name)]) if not res: # Could not find user in the DB. return if bcrypt_cache[phash] != res['pw_hash']: # Password bcrypts do not match. return return await self.get_by_name(name)
def get_from_cred(self, name: str, pw_md5: str) -> None: # Only used cached results - the user should have # logged into bancho at least once. (This does not # mean they're logged in now). # Let them pass as a string for ease of access pw_md5: bytes = pw_md5.encode() if pw_md5 not in glob.cache['bcrypt']: # User has not logged in through bancho. return res = glob.db.fetch('SELECT pw_hash FROM users WHERE name_safe = %s', [Player.ensure_safe(name)]) if not res: # Could not find user in the DB. return if glob.cache['bcrypt'][pw_md5] != res['pw_hash']: # Password bcrypts do not match. return return self.get_by_name(name)
utc_offset = int(s[1]) display_city = s[2] == '1' # Client hashes contain a few values useful to us. # [0]: md5(osu path) # [1]: adapters (network physical addresses delimited by '.') # [2]: md5(adapters) # [3]: md5(uniqueid) (osu! uninstall id) # [4]: md5(uniqueid2) (disk signature/serial num) client_hashes = s[3].split(':')[:-1] pm_private = s[4] == '1' res = await glob.db.fetch( 'SELECT id, name, priv, pw_hash, silence_end ' 'FROM users WHERE name_safe = %s', [Player.ensure_safe(username)]) # Get our bcrypt cache. bcrypt_cache = glob.cache['bcrypt'] if res: # Account exists. # Check their account status & credentials against db. if not res['priv'] & Privileges.Normal: return await packets.userID(-3), 'no' # Password is incorrect. if pw_hash in bcrypt_cache: # ~0.01 ms # Cache hit - this saves ~200ms on subsequent logins. if bcrypt_cache[pw_hash] != res['pw_hash']: return await packets.userID(-1), 'no'