• Stars
    star
    100
  • Rank 338,786 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go package to encode (with random generated salt) and verify passwords

go-password-encoder

Build Status GoDoc Go Report Card

This package in Go provides functions to encode a raw password (example, during registration on a site), and later verify it (example, while logging in to the site).

Functions available:

func Encode(string, *Options) (string, string) {} // takes the raw password along with options, returns generated salt and hex encoded password
func Verify(string, string, string, *Options) bool {} // takes the raw password, the generated salt, and encoded password with options, and returns true or false

The Options struct is used to enable custom options:

type Options struct {
	SaltLen      int
	Iterations   int
	KeyLen       int
	HashFunction func() hash.Hash
}

Passing nil as the last argument in either function resorts to using the default options. The default options are as follows:

  • Length of generated salt for the user is 256
  • Iteration count in PBKDF2 function is 10000
  • Length of encoded key in PBKDF2 function is 512
  • Hash algorithm used is sha512

Hover over to Usage for a complete example.

Installation

go get github.com/anaskhan96/go-password-encoder

Run go test in the package's directory to run tests.

Usage

Following is an example depicting the usage of this package:

package main

import (
	"crypto/md5"
	"fmt"
	"github.com/anaskhan96/go-password-encoder"
)

func main() {
	// Using the default options
	salt, encodedPwd := password.Encode("generic password", nil)
	check := password.Verify("generic password", salt, encodedPwd, nil)
	fmt.Println(check) // true

	// Using custom options
	options := &password.Options{10, 10000, 50, md5.New}
	salt, encodedPwd = password.Encode("generic password", options)
	check = password.Verify("generic password", salt, encodedPwd, options)
	fmt.Println(check) // true
}

Related

More Repositories

1

soup

Web Scraper in Go, similar to BeautifulSoup
Go
2,036
star
2

litfs

A FUSE file system in Go extended with persistent file storage
Go
125
star
3

sesh

A (very) simple elegant shell in Go
Go
33
star
4

Crash-Alert

Android app that uses accelerometer in mobiles to detect collisions while driving and sends location with nearby hospital's number to emergency contacts.
Java
23
star
5

base58check

Go implementation of base58check to encode Bitcoin addresses
Go
11
star
6

Image-Compression-Huffman

Converts images to text, then compresses the text file using Huffman compression
C
9
star
7

ngo-project

Web portal for the NGO Sri Vidyaniketan School built on Node/Express/Mongoose
JavaScript
8
star
8

newtonmath

Rust wrapper for Newton API
Rust
5
star
9

r2ic

A front end compiler to compile basic constructs in Rust to an intermediate code (quadruples) with optimizations
Python
3
star
10

github-stats-bot

Reddit bot giving short description of github repos
Go
3
star
11

go-vapidkeys

Go Package to generate VAPID public and private keys
Go
2
star
12

ODAssignments

Assignments given by OneDirect.
Java
2
star
13

HealthLedger

A virtual ledger built with NodeJS + Mongo to hold all patient records.
HTML
2
star
14

consolia-api

npm module to fetch consolia comics
JavaScript
2
star
15

check-base-encoding

npm module to check base encoding of a particular string
JavaScript
2
star
16

ezlisp

Basic lisp interpreter (Scheme dialect)
Python
1
star
17

Go-AlGo

Basic algorithms implemented in Golang
Go
1
star
18

gitSlack

New received user events on GitHub (user activity feed) posted on Slack
Python
1
star
19

cloud-complete

Unified testing suite for testing applications for Cloud Compliance
HTML
1
star
20

ElectroLight-Explorer

File explorer
Java
1
star
21

config

Personal config on Mac and Linux systems
Shell
1
star
22

anaskhan96.github.io

HTML
1
star
23

SelfieLessActs

Cross Platform Mobile App for SelfieLessActs
JavaScript
1
star
24

DA-Project

Data Analytics project repository, PES University '17
Python
1
star
25

XKCD-Comic-Extension

A Chrome extension that lets you view the latest as well as any random comic from xkcd.
JavaScript
1
star