hashpass

package module
v0.3.3-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

Hashing Passwords with bcrypt.

hashpass is a set of functions utilizing bcrypt to assist in storing hashed passwords for new user registration, and password/hash comparison for user authentication.

Here is an example of how it might be used.

package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/cloud3000/hashpass"
)

func main() {
	passdb := "pass.json" // JSON file where passwords are stored.
	cmd, usr, pas, err := hashpass.GetInfo()
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		os.Exit(1)
	}

	if hashpass.ChkBadpass(pas) {
		fmt.Fprintf(os.Stderr, "Overused Password NOT ALLOWED! [%s]\n", pas)
		os.Exit(2)
	}

	switch strings.ToLower(cmd) {
	case "store":
		err = hashpass.StorePass(usr, pas, passdb)
	case "check":
		err = hashpass.CheckPass(usr, pas, passdb)
	default:
		err = fmt.Errorf("%s is not a valid command", cmd)
	}
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
	}
}

ToDo's:

  1. Add config.json, and code to support it.
  2. Add code to check for pre-existing user before appending a new record to ./data/pass.db

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPass

func CheckPass(u, p, db string) (uint8, error)

CheckPass Finds the (db) record that matches username(u) Compares clear-text password to hashed value found in db

func ChkBadpass

func ChkBadpass(text string) bool

ChkBadpass scans a file (top 1000 most common passwords) looking for a match If a match is found return true, and the password should be allowed.

func GetInfo

func GetInfo() (string, string, string, error)

GetInfo will get command-line parms; cmd, usr, and pas

func StorePass

func StorePass(u, p, db string) (int, error)

StorePass Stores Username(u) and Password(p) in the Flatfile database(db)

  1. Generates the hash value from the password(p)
  2. Populates credential with Username & Password
  3. Marshal credential into json
  4. Appends single record json string to Flatfile(db)
  5. TODO: Before appending, check if username already exists in db.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL