Add a generator of a SafeString.
This commit is contained in:
@@ -7,4 +7,6 @@
|
|||||||
Updated the Links model to have a unique shorten.
|
Updated the Links model to have a unique shorten.
|
||||||
** 0.1.2 <2023-07-06 Thu>
|
** 0.1.2 <2023-07-06 Thu>
|
||||||
Renamed the Links.get_one_by_name to get_one_by_shorten.
|
Renamed the Links.get_one_by_name to get_one_by_shorten.
|
||||||
|
** 0.2.0 <2023-07-07 Fri>
|
||||||
|
Added a generator of a SafeString.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule LinkShortener.Generators.SafeString do
|
||||||
|
@moduledoc """
|
||||||
|
This module provides a generator.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Generate a random string with the length.
|
||||||
|
The string can be used as part of a url.
|
||||||
|
"""
|
||||||
|
def generate(length) do
|
||||||
|
:crypto.strong_rand_bytes(length)
|
||||||
|
|> Base.url_encode64()
|
||||||
|
|> binary_part(0, length)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user