Permalink
Browse files

password hashing

  • Loading branch information...
mjhea0 committed Sep 3, 2014
1 parent 25e636a commit 86c839f5d2af6dbfbc332c1bad25e474ec53afd9
Showing with 68 additions and 6 deletions.
  1. +3 −1 app.py
  2. +9 −0 db_create_users.py
  3. +26 −0 migrations/versions/3e0014fa59ca_.py
  4. +26 −0 migrations/versions/c1b2d6a2aa6_.py
  5. +4 −5 models.py
View
4 app.py
@@ -3,9 +3,11 @@
url_for, request, session, flash
from functools import wraps
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.bcrypt import Bcrypt
# create the application object
# create the application object, pass it into Bcrypt for hashing
app = Flask(__name__)
bcrypt = Bcrypt(app)
# config
import os
View
@@ -0,0 +1,9 @@
from app import db
from models import User
# insert data
db.session.add(User("michael", "michael@realpython.com", "i'll-never-tell"))
db.session.add(User("admin", "ad@min.com", "admin"))
# commit the changes
db.session.commit()
@@ -0,0 +1,26 @@
"""empty message
Revision ID: 3e0014fa59ca
Revises: 4a5b39003781
Create Date: 2014-09-03 16:30:20.119025
"""
# revision identifiers, used by Alembic.
revision = '3e0014fa59ca'
down_revision = '4a5b39003781'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'password')
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('password', sa.VARCHAR(), autoincrement=False, nullable=False))
### end Alembic commands ###
@@ -0,0 +1,26 @@
"""empty message
Revision ID: c1b2d6a2aa6
Revises: 3e0014fa59ca
Create Date: 2014-09-03 16:32:08.805429
"""
# revision identifiers, used by Alembic.
revision = 'c1b2d6a2aa6'
down_revision = '3e0014fa59ca'
from alembic import op
import sqlalchemy as sa
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('password', sa.String(), nullable=True))
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'password')
### end Alembic commands ###
View
@@ -1,4 +1,4 @@
from app import db
from app import db, bcrypt
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
@@ -28,14 +28,13 @@ class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
email = db.Column(db.String, nullable=False)
password = db.Column(db.String, nullable=False)
password = db.Column(db.String)
posts = relationship("BlogPost", backref="author")
def __init__(self, name, email, password, favorite_color):
def __init__(self, name, email, password):
self.name = name
self.email = email
self.password = password
self.favorite_color = favorite_color
self.password = bcrypt.generate_password_hash(password)
def __repr__(self):
return '<name {}'.format(self.name)

0 comments on commit 86c839f

Please sign in to comment.