Coder Social home page Coder Social logo

twin / golang-auth-sessions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lugbit/golang-auth-sessions

0.0 1.0 0.0 608 KB

A custom sign up, authentication and session handling in Go.

License: MIT License

Go 12.61% CSS 0.04% PLpgSQL 1.92% JavaScript 85.43%

golang-auth-sessions's Introduction

Golang authentication and sessions

A custom registration, authentication and session handling implemented in Golang and MySQL.

Motivation

This project was started purely as a learning tool to aid myself with learning Golang and specifically web development with Golang. I wanted to incorporate Go with a RDBMS such as MySQL as well as implement other features such as account verification upon sign up and sessions without the use of a framework.

Screenshots

activation-reminder

login

profile

register

Tech/packages used

Features

  • Registration and activation
    • Activation link is sent to the user's registration email with a UUID token embedded upon signing up. This one time use link must be used before it is expired or it will not activate the associated account.
    • Activation links are one time use. Once clicked, it will be marked as used in the database and cannot be used again.
    • Activaton links can be resent by visiting the /send-activation route which will generate a new activation link with a new expiry date.
  • Authentication
    • Registered users with activated accounts can login with their email and password.
    • The email address the user enters is checked against the database. If the email exists, the password entered is hashed and compared against the hashed password entry in the database and if the hash matches, the user is logged in and a session is created.
  • Sessions
    • Once a user successfully authenticates, a session is created.
    • The UUID generated upon logging in is inserted in the sessions table with the user's unique id.
    • A cookie is sent to the client with the same UUID that was inserted in the database.
    • When a user makes a request for a secured route e.g. /my-profile, the session cookie is received by the server and verified against the sessions table. If the same UUID in the cookie is also present in the sessions table, the user is granted access to the secured route.
    • Sessions and cookies have a maximum life before they expire, once expired, the user will need to login again.
    • Sessions and cookies are automatically renewed when the user makes a request to any secured routes. This will reset the max life of the session and cookie.
    • Session entries along with the session cookie is destroyed upon logging out.
  • Input validation
    • The registration, login and any routes with input forms are validated to make sure they are not empty, have the correct format or unique if a user is entering their email address on sign up.

Setup

  • Load the MySQL database schema located at ./static/db/userAuthDBSchema.sql
  • Set the app environment variables located at ./.env
    • DB_USERNAME = Your MySQL server username
    • DB_PASSWORD = Your MySQL server password
    • DB_ADDRESS = Your MySQL server address
    • DB_PORT = Your MySQL server port
    • DB_NAME = The database name, the default is "userAuthDB" as set on the schema.
    • SENDER_ADDRESS = Verification link sender email address
    • SENDER_PASSWORD = Verification link sender email address password
    • SMTP_SERVER = Verification link sender email address SMTP server
  • Build the binary by running go build and then run the executable
go build

  • Visit localhost:8080 on your web browser

Credits

Thanks to Todd McLeod and particularly his course on Udemy(Course Repo).

License

MIT License

Copyright (c) 2018 Marck Muñoz

golang-auth-sessions's People

Contributors

lugbit 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.