Coder Social home page Coder Social logo

git's Introduction

Create a simple authentication system

an alternative to the hopelessly boring hello world examples for an introduction to git

Start creating a script called auth.py

Expected usage:

  • run the script
  • the script asks for username and password
  • if the user is known and password is correct: print the password database
  • if the user is not known, ask to add it to the password database
  • if a user has been added, store the updated database to disk

Basic API:

  • a function get_credentials that asks for username and password
  • a function authenticate that checks if user is in the password database and that the password is correct
  • a function add_user to add a new user with its password to the database
  • a function read_pwdb to read the password database from disk
  • a function write_pwdb to write the password database to disk

Suggestions:

  • the database can be a simple dictionary {username: password}
  • the database can be serialized to disk with pickle
  • to experiment you can store the database on a temporary directory
  • remember to write the database to disk every time you add a new user

Later, think about the following problems:

  • should we return different errors if username is not known or password is wrong? ⟶ do not leak valid usernames
  • password hashing ⟶ do not store passwords in clear text (database could be stolen, admins are nosy), do not store passwords at all but only its hash (database could be stolen)
  • password salting ⟶ different users with same passwords should not have same hash ⟶ cracking one does not crack all: mitigates dictionary attacks, see below)

Addition to the basic API:

  • a function pwhash that given a password and a salt returns a hash
  • a function get_salt that returns a unique salt

Try to crack it! (Advanced)

Notes

To make it for real:

  • insecure temporary file (symlink race attack) ⟶ tempfile and its context managers
  • better way of generating passwords or random tokens: the secrets module
  • cracking a password database is a form of art, see for example the John the Ripper password cracker

git's People

Contributors

otizonaizit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.