Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darwintantuco/the_big_username_blacklist
Elixir library for The-Big-Username-Blacklist (Opinionated username blacklist).
https://github.com/darwintantuco/the_big_username_blacklist
Last synced: 18 days ago
JSON representation
Elixir library for The-Big-Username-Blacklist (Opinionated username blacklist).
- Host: GitHub
- URL: https://github.com/darwintantuco/the_big_username_blacklist
- Owner: darwintantuco
- License: mit
- Created: 2019-06-08T12:08:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-18T11:43:18.000Z (over 4 years ago)
- Last Synced: 2024-10-18T05:07:43.005Z (21 days ago)
- Language: Elixir
- Homepage:
- Size: 28.3 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# TheBigUsernameBlacklist
![Elixir CI](https://github.com/darwintantuco/the_big_username_blacklist/workflows/Elixir%20CI/badge.svg)
This library lets you validate usernames against a blacklist. The blacklist data is based on the data from [The-Big-Username-Blacklist](https://github.com/marteinn/The-Big-Username-Blacklist) and contains privilege, programming terms, section names, financial terms and actions.
You can try the blacklist using the tool [Username checker](http://marteinn.github.io/The-Big-Username-Blacklist-JS/).
## Installation
The package can be installed by adding `the_big_username_blacklist` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:the_big_username_blacklist, "~> 0.1.2"}
]
end
```## Usage
```elixir
iex> TheBigUsernameBlacklist.valid?("tonystark")
trueiex> TheBigUsernameBlacklist.valid?("logout")
false
```### Extending blacklist
This is useful when there are existing routes or reserved words that you don't want to be a valid username.
```elixir
iex> custom_blacklist = ["about-me", "contact-us"]iex> TheBigUsernameBlacklist.valid?("about-me", custom_blacklist)
falseiex> TheBigUsernameBlacklist.valid?("brucewayne", custom_blacklist)
true
```### With Ecto
```elixir
def create_user_changeset(%User{} = user, attrs \\ %{}) do
user
|> user_changeset(attrs)
|> validate_required([:email, :username, :first_name, :last_name])
|> validate_username()
enddefp validate_username(%{changes: %{username: username}} = changeset) do
if TheBigUsernameBlacklist.valid?(username) do
changeset
else
add_error(changeset, :username, "Invalid username.")
end
enddefp validate_username(changeset), do: changeset
```For more info, check [https://hexdocs.pm/the_big_username_blacklist](https://hexdocs.pm/the_big_username_blacklist).
## Other packages
[The-Big-Username-Blacklist](https://github.com/marteinn/The-Big-Username-Blacklist) has been ported to different languages
- [python](https://github.com/marteinn/the-big-username-blacklist-python)
- [node](https://github.com/marteinn/the-big-username-blacklist-js)
- [ruby](https://github.com/unlearned/the_big_username_blacklist)## License
MIT