SuNNjek / identity

Go library implementing the ASP.NET Core identity password hashing algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

identity

CI status GoDoc

Go library implementing the ASP.NET Core identity password hashing algorithm

Install

go get -u github.com/SuNNjek/identity

Usage

Generate new password

package example

import (
    "github.com/SuNNjek/identity"
)

func main() {
    password := "my password"

    // Generate new random salt
    salt, _ := identity.GenerateSalt(identity.DefaultSaltLength)

    // Hash the password using the default parameters
    hash := identity.HashPasswordV3(
        []byte(password),
        salt,
        identity.DefaultHashAlgorithm,
        identity.DefaultIterations,
        identity.DefaultNumBytes)

    // ...
}

Verify existing password hash

package example

import (
    "github.com/SuNNjek/identity"
)

func main() {
    // Placeholder, replace with your logic to retrieve password hash
    hashedPassword := getPasswordHash()
    enteredPassword := "my password"

    // Verify the entered password against the hashed one
    passwordsMatch := identity.Verify(hashedPassword, []byte(enteredPassword))

    // ...
}

About

Go library implementing the ASP.NET Core identity password hashing algorithm

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 100.0%