Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flask authentication user without database

class User(UserMixin):

    def __init__(self, username, hash):
        self.name = username
        self.hash = hash

    @property
    def id(self):
        return self.name


@self.server.route('/api/login', methods=['GET', 'POST'])
def login():
    user = load_user(request.values.get('username'))
    if user and user.hash == request.values.get('hash'):
        login_user(user)
        return jsonify(status='ok', username=user.username)
    else:
        return jsonify(status='error', message='wrong username or hash')
Comment

PREVIOUS NEXT
Code Example
Python :: dot operator in python 
Python :: python callable type hint 
Python :: pyodbc cursor create list of dictionaries 
Python :: pandas round floats 
Python :: python train test val split 
Python :: filter dict by list of keys python 
Python :: initialize a 2d list python 
Python :: append write python 
Python :: python __str__ vs __repr__ 
Python :: astype python 
Python :: read list from txt python 
Python :: convert a string into a list in Python 
Python :: django queryset count 
Python :: crawl a folder python 
Python :: python string cut last n characters 
Python :: validate ip address 
Python :: python save button 
Python :: to str python 
Python :: get file in file zip python 
Python :: envScriptsactivate.ps1 : File 
Python :: create button in pyqt 
Python :: pandas count 
Python :: python cv2 canny overlay on image 
Python :: add reaction discord.py 
Python :: concatenate string and int python 
Python :: python generator example 
Python :: serialize keras model 
Python :: create file in a specific directory python 
Python :: random.randint 
Python :: reversed python 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =