Slide 1

Slide 1 text

Password Security From Zero to Hero @rdegges

Slide 2

Slide 2 text

I’m Randall Degges Developer Evangelist, Stormpath https://stormpath.com Pythonista 103 github projects, mostly python

Slide 3

Slide 3 text

“Why should I care about password security?”

Slide 4

Slide 4 text

Nobody teaches it :(

Slide 5

Slide 5 text

Everyone messes it up!

Slide 6

Slide 6 text

LOVE YOUR USERS

Slide 7

Slide 7 text

Security Samurai YOU

Slide 8

Slide 8 text

The Basics

Slide 9

Slide 9 text

You need to store passwords.

Slide 10

Slide 10 text

Plain Text "rdegges","omgmypass" "rocketspaceadmin","abc123" "liljohn","OKKAAAYYYY!"

Slide 11

Slide 11 text

This sucks.

Slide 12

Slide 12 text

If someone gets access to your database, game over.

Slide 13

Slide 13 text

Then you have to deal with this.

Slide 14

Slide 14 text

“But Randall, who would do that?”

Slide 15

Slide 15 text

...

Slide 16

Slide 16 text

http://plaintextoffenders.com

Slide 17

Slide 17 text

Introducing the Hash

Slide 18

Slide 18 text

“What is a hash?”

Slide 19

Slide 19 text

It’s basically a stupid function that converts a string into garbage.

Slide 20

Slide 20 text

"rdegges","omgmypass" "rocketspaceadmin","abc123" "liljohn","OKKAAAYYYY!" "rdegges","3e3faeabbd3e98c6cedb91ad46551014" "rocketspaceadmin","e99a18c428cb38d5f260853678922e03" "liljohn","9bc50c01de2edd2bdc488d94751b4a1e" hash()

Slide 21

Slide 21 text

All hashes are unique.

Slide 22

Slide 22 text

You cannot ‘reverse’ a hash.

Slide 23

Slide 23 text

There are lots of hashing algorithms! MD5 SHA1 SHA256 SHA512 PBKDF2 BCRYPT SCRYPT

Slide 24

Slide 24 text

Most suck though. MD5 SHA1 SHA256 SHA512 PBKDF2 BCRYPT SCRYPT

Slide 25

Slide 25 text

Let’s talk about why.

Slide 26

Slide 26 text

Brute Force

Slide 27

Slide 27 text

You basically just try every possible password.

Slide 28

Slide 28 text

from hashlib import md5 from itertools import chain, product from string import printable from sys import argv def bruteforce(length): return ( ''.join(candidate) for candidate in chain.from_iterable( product( printable, repeat = i ) for i in range(1, length + 1) ) ) for pw in bruteforce(int(argv[2])): if md5(pw).hexdigest() == argv[1]: print 'Cracked hash: %s!' % argv[1] print 'Password is: %s' % pw break

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

brutal! >>> from brute import brute >>> for s in brute(length=10): ... print s $ pip install brute

Slide 31

Slide 31 text

Rainbow Tables

Slide 32

Slide 32 text

password | md5 | sha1 -------------+----------------------------------+------------------------------------------ omgmypass | 364a7aeccbc2b0f8b9bcf07ae0dd4748 | 8a4dd43ae7291b91f995f6d3153e926211ebae44 abc123 | e99a18c428cb38d5f260853678922e03 | 6367c48dd193d56ea7b0baad25b19455e529f5ee OKKAAAYYYY! | 9bc50c01de2edd2bdc488d94751b4a1e | 9a1dc4294bbc5f6a35b5eed899386a2035a2ebde A big ass database of passwords and hashes.

Slide 33

Slide 33 text

TONS of these.

Slide 34

Slide 34 text

Collisions What happens when two different passwords have the same password hash.

Slide 35

Slide 35 text

Salts

Slide 36

Slide 36 text

You basically just create a random string and prepend it to passwords to make brute forcing harder.

Slide 37

Slide 37 text

hash(salt+pass)

Slide 38

Slide 38 text

salt$hash(salt+pass) hash(pass)

Slide 39

Slide 39 text

"rdegges","salt$hash" "rocketspaceadmin","salt$hash" "liljohn","salt$hash"

Slide 40

Slide 40 text

Salts are great because attackers can’t use rainbow tables, and must brute force every password individually.

Slide 41

Slide 41 text

Speeeeeeeeeed!

Slide 42

Slide 42 text

Slower is better.

Slide 43

Slide 43 text

The slower a hash function is, the longer it takes to brute force.

Slide 44

Slide 44 text

md5(pass) ~ .1 sec bcrypt(pass) ~ 2 sec = 20x slower

Slide 45

Slide 45 text

bcrypt is slow “I’m slow.”

Slide 46

Slide 46 text

>>> from bcrypt import gensalt, hashpw >>> >>> hash = hashpw('omghi!', gensalt()) >>> if hashpw('omghi!', hash) == hash: ... print 'password valid!' ... 'password valid!'

Slide 47

Slide 47 text

bcrypt ● Been around for a long time. ● Very well peer reviewed. ● Widely considered the best option for password hashing. ● Easy to use in Python. ● Orders of magnitude slower than almost every other hashing function (ask me more about this later).

Slide 48

Slide 48 text

“Use bcrypt or I will be upset with you.” -Randall

Slide 49

Slide 49 text

$ pip install bcrypt

Slide 50

Slide 50 text

# settings.py PASSWORD_HASHERS = ( 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', 'django.contrib.auth.hashers.BCryptPasswordHasher', 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', 'django.contrib.auth.hashers.SHA1PasswordHasher', 'django.contrib.auth.hashers.MD5PasswordHasher', 'django.contrib.auth.hashers.CryptPasswordHasher', )

Slide 51

Slide 51 text

Security is hard.

Slide 52

Slide 52 text

Stormpath User Management API for Developers ● Authentication ● User Profiles ● Groups and Roles ● Awesome Python Support ● API Authentication ● Social Login ● SSO ● Hosted Login

Slide 53

Slide 53 text

So... ● Store passwords with bcrypt. ● Check out stormpath.com and play around with it! It’s awesome! ● If you liked this talk, tweet @gostormpath.

Slide 54

Slide 54 text

You are Awesome randall@stormpath.com @rdegges