def check_credentials(username=None, password=None, token=None, admin_login='******', headers=None): """Verifies credentials for username and password. Returns True and the user group on success or False and no user group""" if username and password: if plexpy.CONFIG.HTTP_PASSWORD: user_details = {'user_id': None, 'username': username} if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): return True, user_details, 'admin' elif not plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: return True, user_details, 'admin' if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS): plex_login = plex_user_login(username=username, password=password, token=token, headers=headers) if plex_login is not None: return True, plex_login[0], plex_login[1] return False, None, None
def post(self): """ # handles POST requests sent to / # Generally these are login requests """ if ( not self.is_logged_in() ): # open database and look up input username self.set_header("Content-Type", "text/html") user = self.graph.users.index.lookup(\ userid=self.get_argument("username")) if ( user is None ): self.render_template("landingpage.html",\ error_message="Username or password was incorrect.\n") else : user = user.next() # check that password is correct if check_hash(self.get_argument("password"),user.password): # save the session cookie self.set_secure_cookie("userid", user.userid) self.set_secure_cookie("eid", str(user.eid)) self.redirect("/") else: self.render_template("landingpage.html",\ error_message="Username or password was incorrect.\n")
def hash_cb(rows): if len(rows) == 0: return_d.callback(False) # return False if user not in DB return username_type, password_hash = rows[0] return_d.callback(check_hash(password, password_hash)) # check hash and return result return
def hash_cb(rows): if len(rows) == 0: return_d.callback(False) # return False if user not in DB return username_type, password_hash = rows[0] if password_hash == "": return_d.callback(True) # user's password is not yet set - return True always. return return_d.callback(check_hash(password, password_hash)) # check hash and return result return
def check_credentials(username, password, admin_login='******'): """Verifies credentials for username and password. Returns True and the user group on success or False and no user group""" if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): return True, u'admin' elif username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: return True, u'admin' elif not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS and user_login(username, password): return True, u'guest' else: return False, None
def check_credentials(username, password, admin_login='******'): """Verifies credentials for username and password. Returns True and the user group on success or False and no user group""" if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): return True, u'admin' elif username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: return True, u'admin' elif not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS and user_login( username, password): return True, u'guest' else: return False, None
def get_apikey(self, username='', password=''): """ Get the apikey. Username and password are required if auth is enabled. Makes and saves the apikey if it does not exist. ``` Required parameters: None Optional parameters: username (str): Your Tautulli username password (str): Your Tautulli password Returns: string: "apikey" ``` """ data = None apikey = hashlib.sha224(str( random.getrandbits(256)).encode('utf-8')).hexdigest()[0:32] if plexpy.CONFIG.HTTP_USERNAME and plexpy.CONFIG.HTTP_PASSWORD: authenticated = False if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): authenticated = True elif not plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: authenticated = True if authenticated: if plexpy.CONFIG.API_KEY: data = plexpy.CONFIG.API_KEY else: data = apikey plexpy.CONFIG.API_KEY = apikey plexpy.CONFIG.write() else: self._api_msg = 'Authentication is enabled, please add the correct username and password to the parameters' else: if plexpy.CONFIG.API_KEY: data = plexpy.CONFIG.API_KEY else: # Make a apikey if the doesn't exist data = apikey plexpy.CONFIG.API_KEY = apikey plexpy.CONFIG.write() return data
def check_credentials(username, password, admin_login='******'): """Verifies credentials for username and password. Returns True and the user group on success or False and no user group""" if plexpy.CONFIG.HTTP_PASSWORD: if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): return True, 'tautulli admin' elif not plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: return True, 'tautulli admin' if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS): plex_login = user_login(username, password) if plex_login is not None: return True, plex_login return False, None
def performLogin(username, password): result = { "error": True, "errorMessage": "Unknown error", "user": 0, "username": "" } try: if username and password: print "performing login operation: USER[" + username + "] Password[" + password + "]" conn = mysql.connect() cursor = conn.cursor() cursor.callproc('sp_validateLogin', (username, )) data = cursor.fetchall() if len(data) > 0: _storedPassword = data[0][2] _storedUserId = data[0][0] if check_hash(password, _storedPassword): result["error"] = False result["user"] = _storedUserId result["username"] = username result["errorMessage"] = "" else: result["errorMessage"] = "Username or Password is wrong!!" else: result["errorMessage"] = "Username not found!!" conn.close() else: result["errorMessage"] = "Invalid data!!" except Exception as e: print "error while logging in." print str(e) result["errorMessage"] = str(e) finally: print result return result
pwhash = u.pwhash except User.DoesNotExist: log.debug("User {0} does not exist".format(username)) return False except Exception, e: raise match = False # Is this a plain-text password in the database?!? OK, we'll do this ... if not pwhash.startswith('PBKDF2$'): match = pwhash == password log.debug('Plain-text password (bah!) match for %s (%s)' % (username, match)) else: match = hp.check_hash(password, pwhash) log.debug('Hash match for %s (%s): %s' % (username, pwhash, match)) if match == True and apns_token is not None: tstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime()) try: q = User.update(token=apns_token, tstamp=tstamp).where(User.username == username) q.execute() log.info("Token {0} updated for username={1}".format( apns_token, username)) except Exception, e: log.error("Cannot update User {0} with token {1}: {2}".format( username, apns_token, str(e))) log.info("Password for username={0} was accepted".format(username))
try: u = User.get(User.username == username) pwhash = u.pwhash except User.DoesNotExist: log.debug("User {0} does not exist".format(username)) return False except Exception, e: raise match = False # Is this a plain-text password in the database?!? OK, we'll do this ... if not pwhash.startswith('PBKDF2$'): match = pwhash == password log.debug('Plain-text password (bah!) match for %s (%s)' % (username, match)) else: match = hp.check_hash(password, pwhash) log.debug('Hash match for %s (%s): %s' % (username, pwhash, match)) if match == True and apns_token is not None: tstamp = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime()) try: q = User.update(token = apns_token, tstamp = tstamp).where(User.username == username) q.execute() log.info("Token {0} updated for username={1}".format(apns_token, username)) except Exception, e: log.error("Cannot update User {0} with token {1}: {2}".format(username, apns_token, str(e))) log.info("Password for username={0} was accepted".format(username)) return match