rlivsey / elixir-setaria

Setaria is OATH One Time Passwords Library for Elixir.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setaria

Setaria is OATH One Time Passwords Library for Elixir. This is wrapper of POT.

Installation

If available in Hex, the package can be installed as:

  1. Add setaria to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:setaria, "~> 0.1.0"}]
end
```
  1. Ensure setaria is started before your application:
```elixir
def application do
  [applications: [:setaria]]
end
```

Usage

NOTE: Some parameters are fixed now. The timestep is 30, digits is 6, and digest method is sha.

  • create hotp

    # base32encoded secret
    hotp = Setaria.hotp(encoded_secret, counter)
    
    # raw secret
    hotp = Setaria.hotp(secret, counter, encoded_secret: false)
  • validate hotp

    # base32encoded secret
    is_valid = Setaria.valid_hotp(expected_token, encoded_secret, counter)
    
    # raw secret
    is_valid = Setaria.valid_hotp(expected_token, secret, counter, encoded_secret: false)
  • create totp

    # base32encoded secret
    totp = Setaria.totp(encoded_secret)
    totp = Setaria.totp(encoded_secret, timestamp)
    
    # raw secret
    totp = Setaria.totp(secret, encoded_secret: false)
    totp = Setaria.totp(secret, timestamp, encoded_secret: false)
  • validate hotp

    # base32encoded secret
    is_valid = Setaria.valid_totp(expected_token, encoded_secret)
    is_valid = Setaria.valid_totp(expected_token, encoded_secret, timestamp)
    
    # raw secret
    is_valid = Setaria.valid_totp(expected_token, secret, encoded_secret: false)
    is_valid = Setaria.valid_totp(expected_token, secret, timestamp, encoded_secret: false)

About

Setaria is OATH One Time Passwords Library for Elixir.


Languages

Language:Elixir 100.0%