spring_password_encoder

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

go-spring-password-encoder

Build Latest Release Go Report Card License

Spring compatible password encoders written in golang

Usage

Add entry to go.mod file:

[...]

go 1.16

require (
    github.com/cbuschka/go-spring-password-encoder v1.0.0
    [...]
)

import the package fromn within your code:

import "github.com/cbuschka/go-spring-password-encoder"
SHA256PasswordEncoder (called StandardPasswordEncoder by spring)

Hint: This password encoder is considered legacy and too weak.

Hash and encode password
encoder := spring_password_encoder.NewDefaultSHA256PasswordEncoder()

encodedPasswordHash, err := encoder.Encode("asdfasdf")
Compare plain text password with hashed password
encoder := spring_password_encoder.NewDefaultSHA256PasswordEncoder()

encodedPasswordHash, err := encoder.Encode("asdfasdf")

See sha256 password encoder test

BCryptPasswordEncoder
Hash and encode password
encoder := spring_password_encoder.NewDefaultBCryptPasswordEncoder()

encodedPasswordHash, err := encoder.Encode("asdfasdf")
Compare plain text password with hashed password
encoder := spring_password_encoder.NewDefaultBCryptPasswordEncoder()

encodedPasswordHash, err := encoder.Encode("asdfasdf")

See bcrypt password encoder test

License

Copyright (c) 2021 by Cornelius Buschka.

Apache License, Version 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BCryptPasswordEncoder added in v0.1.0

type BCryptPasswordEncoder struct {
	// contains filtered or unexported fields
}

BCryptPasswordEncoder is compatible to spring's BCryptPasswordEncoder.

func (*BCryptPasswordEncoder) Encode added in v0.1.0

func (encoder *BCryptPasswordEncoder) Encode(plainPassword string) (string, error)

func (*BCryptPasswordEncoder) Matches added in v0.1.0

func (encoder *BCryptPasswordEncoder) Matches(plainPassword string, encodedPasswordHash string) (bool, error)

type PasswordEncoder

type PasswordEncoder interface {
	Matches(plainPassword string, encodedPasswordHash string) (bool, error)

	Encode(plainPassword string) (string, error)
}

PasswordEncoder is the interface to password encoding and matching

func NewBCryptPasswordEncoder added in v0.1.0

func NewBCryptPasswordEncoder(strength int) PasswordEncoder

func NewDefaultBCryptPasswordEncoder added in v0.1.0

func NewDefaultBCryptPasswordEncoder() PasswordEncoder

func NewDefaultSHA256PasswordEncoder

func NewDefaultSHA256PasswordEncoder() PasswordEncoder

NewDefaultSHA256PasswordEncoder creates a SHA256 password encoder with default params

func NewSHA256PasswordEncoder

func NewSHA256PasswordEncoder(saltLengthBytes int, iterations int) PasswordEncoder

NewSHA256PasswordEncoder creates a SHA256 password encoder

type SHA256PasswordEncoder

type SHA256PasswordEncoder struct {
	// contains filtered or unexported fields
}

SHA256PasswordEncoder is compatible to spring's StandardPasswordEncoder.

func (*SHA256PasswordEncoder) Encode added in v0.1.0

func (encoder *SHA256PasswordEncoder) Encode(plainPassword string) (string, error)

func (*SHA256PasswordEncoder) Matches

func (encoder *SHA256PasswordEncoder) Matches(plainPassword string, encodedPasswordHash string) (bool, error)

Matches checks if password is the same as an encoded password hash has been created from

Jump to

Keyboard shortcuts

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