Crowdhailer

Crowdhailer

Creator of Raxx

Secure masked tokens for API keys and password resets

My current application needs secure tokens for password reset.
These tokens do not contain any state, the security model is that the bearer will use them to talk to the server and the server can look up the associated state.
Also ideally these tokens should be as short as possible.

Currently what I am doing is associating an id (32 bit integer) with a secret (128 bit).
The id and a masked version of the secret are stored in the database.

  defp mask(secret) do
    Base.url_encode64(:crypto.hash(:sha256, secret))
  end

The token given to the user is a base64 url encoded string with both id and secret.

  def serialize(id, secret) when id <= @maximum_id_value do
    Base.url_encode64(<<id::32, 0::8, secret::binary>>)
  end

Features:

  • My server cannot generate the token so user can only download it at the time of generation
  • I can generate a prefix (the first 6 characters come from the id) for a user which is helpful for managing the keys.

My Questions are:

  • Is this secure?
  • Are there any standards for this type of token?
  • If no standards are there any libraries that do just this. I have found libraries that do more but I want just the token creation and serializing and parsing.

First Post!

LostKobrakai

LostKobrakai

If you have associated state can you store the token there as well? If so I guess :crypto.strong_rand_bytes(n) + wherever hashing you prefer should be enough.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement