Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating UUIDs in Elixir

Tags:

elixir

What's a canonical way to generate UUIDs in Elixir? Should I necessarily use the library https://hex.pm/packages/uuid or is there a built-in library? I better have less dependencies and do more work than vise versa, therefore if I can generate in Elixir with an external dependency, it'll better go with it.

like image 450
Jodimoro Avatar asked May 20 '17 05:05

Jodimoro


People also ask

How are UUIDs generated?

UUID was standardized by the Open Software Foundation (OSF), becoming a part of the Distributed Computing Environment (DCE). Different versions of UUID follow the RFC 4122 specification. UUIDs are generated using an algorithm based on a timestamp and other factors such as the network address.

How is UUID v4 generated?

A Version 4 UUID is a universally unique identifier that is generated using random numbers. The Version 4 UUIDs produced by this site were generated using a secure random number generator.

How many UUIDs can exist?

(Technically, it's not impossible that the same UUID we generate could be used somewhere else, but with 340,282,366,920,938,463,463,374,607,431,768,211,456 different possible UUIDs out there, the chances are very slim).

Can UUID be brute forced?

Sandwich Attack: A New Way Of Brute Forcing UUIDs Once an attacker knows the web application uses UUID v1 for generating the password reset link, they could take the approach listed below to guess the right token for an arbitrary account: 1.


3 Answers

import Ecto

uuid = Ecto.UUID.generate
like image 50
Tommy Avatar answered Sep 21 '22 05:09

Tommy


If you're using elixir with ecto, you can always use Ecto.UUID https://hexdocs.pm/ecto/Ecto.UUID.html

like image 28
Navin Peiris Avatar answered Sep 21 '22 05:09

Navin Peiris


The canonical way to generate a globally unique reference in Elixir is with make_ref/0.

From the documentation:

Returns an almost unique reference.

The returned reference will re-occur after approximately 2^82 calls; therefore it is unique enough for practical purposes.

like image 29
James Robey Avatar answered Sep 18 '22 05:09

James Robey