title: Python Flask Authenticaton without a Database
body: <p>I'm attempting to simplify a Flask project by eliminating the use of any database. This will eliminate the need to use SQLAlchemy.</p>
  
  <p>I'm having trouble duplicating the same login mechanism that exist with verifying the username and passwords that I learned about in a Flask tutorial.</p>
  
  <p>I found some example code on-line and attempted to combine the two. I've read as much of the documentation as I can but I am left scratching my head about extracting a valid UserMixin object as this is required to login to the Flask app when using the Flask.Login extension.</p>
  
  <p>I would be eternally grateful if someone could help me overcome my code deficiencies below to get them working well together.</p>
  
  <p>Here is the view:</p>
  
  <pre><code>from flask import render_template, redirect, request, url_for, flash
  from flask.ext.login import login_user, logout_user, login_required
  from . import auth
  from .forms import LoginForm
  from ..models import User, load_user
  
  @auth.route('/login', methods=['GET','POST'])
  def login():
      form = LoginForm()
      if form.validate_on_submit():
      user = User.get(form.userName.data)
      user = load_user(user)
      if user is not None:
          login_user(user, form.remember_me.data)
          flash('You are now logged in!')
          return redirect(request.args.get('next') or url_for('main.index'))
      flash('Invalid username or password')
  return render_template('auth/login.html', form=form)
  </code></pre>
  
  <p>Here is the model:</p>
  
  <pre><code>from flask.ext.login import UserMixin
  from . import login_manager
  
  @login_manager.user_loader
  def load_user(user):
      return User.get(user)
  
  class User(UserMixin):
  
  # proxy for a database of users
  user_database = {u"user": (u"user", u"password"),u"admin": (u"admin", u"password")}
  
  def __init__(self, username, password):
      self.id = username
      self.password = password
  
  @classmethod
  def get(cls,userName):
      return cls.user_database.get(userName)
  </code></pre>
  
  <p>The problem is that I cannot find a way to instantiate the user object correctly to work with the other Flask Login methods. I keep getting errors not matter what variation of the code I do.</p>