Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxdeviant/aragorn2
https://github.com/maxdeviant/aragorn2
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/maxdeviant/aragorn2
- Owner: maxdeviant
- License: mit
- Created: 2024-05-27T20:41:54.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-05-29T03:56:57.000Z (7 months ago)
- Last Synced: 2024-05-29T15:14:00.178Z (7 months ago)
- Language: Gleam
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# aragorn2
[![Package Version](https://img.shields.io/hexpm/v/aragorn2)](https://hex.pm/packages/aragorn2)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/aragorn2/)
![Erlang-compatible](https://img.shields.io/badge/target-erlang-b83998)Secure password hashing, powered by Argon2.
## Platform support
`aragorn2` uses a [NIF](https://www.erlang.org/doc/system/nif) to provide the Argon2 implementation. This NIF leverages the [`argon2`](https://crates.io/crates/argon2) crate, which is a pure Rust implementation of Argon2.
Precompiled binaries are available for the following platforms for your convenience:
| OS | Architecture(s) |
| ------- | --------------- |
| Linux | x86_64 |
| macOS | aarch64, x86_64 |
| Windows | x86_64 |## Installation
```sh
gleam add aragorn2
```## Usage
```gleam
import aragorn2
import gleam/iopub fn main() {
// Create a hasher to use to hash and verify passwords.
//
// You can customize the hasher's parameters, but be mindful of the security
// implications! The defaults are based on the current OWASP recommendations,
// so don't change them unless you know what you are doing.
let hasher = aragorn2.hasher()// Provide a plaintext password to be hashed:
let assert Ok(hashed_password) =
aragorn2.hash_password(hasher, <<"correct horse battery staple":utf8>>)
// This will return a hashed password that you can store (e.g., in your database).
// Reminder: Don't print out your hashed passwords in production.
io.debug(hashed_password)
// "$argon2id$v=19$m=19456,t=2,p=1$SgDirmQl/Revk9+l7XtpZw$fz3xDI6cocCYpNB63FmMV4PhRpRTBK8KMuhYaWnAIKc"// When a user enters their candidate password, check it against the hashed
// password.
//
// When the candidate password does not match, an `Error` will be returned.
case
aragorn2.verify_password(
hasher,
candidate: <<"wrong password":utf8>>,
hash: <>,
)
{
Ok(Nil) -> io.println("You're in!")
Error(Nil) -> io.println("Oops, wrong password!") // <--
}// When the password does match, an `Ok` will be returned.
case
aragorn2.verify_password(
hasher,
candidate: <<"correct horse battery staple":utf8>>,
hash: <>,
)
{
Ok(Nil) -> io.println("You're in!") // <--
Error(Nil) -> io.println("Oops, wrong password!")
}
}
```