def gen_session(self, username): token = Token() self.user = username hA1 = hash_all(self.user) hA2 = hash_all(token.ip, token.uri) session = digest(hA1, hA2, self.qop, self.realm) self.sessions[hA1] = session return session
def authenticate(self): auth = request.authorization if auth is None: raise Challenge(self) self.check_header(auth) self.check_nonce(auth) hA1 = self.get_key(auth.username) hA2 = hash_all(request.method, auth.uri) if hA1 is None: raise Unauthorized() if auth.response != digest(hA1, hA2): raise Unauthorized()
def add_headers(self, response): response = make_response(response) auth = request.authorization hA1 = self.get_key(auth.username) hA2 = hash_all('', auth.uri) rspauth = digest(hA1, hA2) response.headers['Authentication-Info'] = dump_header({ 'rspauth': rspauth, 'qop': auth.qop, 'cnonce': auth.cnonce, 'nc': auth.nc }) return response
def singUp(): data = request.json nome = data.get("nome") email = data.get("email") senha = data.get("senha") ddd = data.get("ddd") sexo = data.get("sexo") hashed_pwrd = hash_all(email, realm, senha) query = """INSERT INTO table_usuario (nome, email, senha, ddd, sexo) VALUES ('"""+\ str(nome)+"""','"""+str(email)+"""','"""+str(hashed_pwrd)+"""',"""+ddd+""",'"""+str(sexo)+"""')""" print(query) response = json.dumps(consulta_db.update_BD(query)) response = make_response(response) return response
def wrapper(username, password, *args, **kargs): password = hash_all(username, self.realm, password) return func(username, password, *args, **kargs)
def logout(self): hA1 = hash_all(auth.user) del self.sessions[hA1] self.user = '' return False
def check_session(self): if self.user is None: return False hA1 = hash_all(self.user) return self.sessions.get(hA1, False)
def check_password(self, hashed_password, user_pass, username): return hashed_password == hash_all(username, self.realm, user_pass)