Skip to content

Instantly share code, notes, and snippets.

@weiss
Created November 21, 2024 17:27
Show Gist options
  • Save weiss/0681aa51728ce47e00935490afcf73c5 to your computer and use it in GitHub Desktop.
Save weiss/0681aa51728ce47e00935490afcf73c5 to your computer and use it in GitHub Desktop.
Example of an ejabberd authentication module written in Gleam
import gleam/list
const credentials = [
#("alice", "l0vesBob"),
#("bob", "l0vesAlice"),
#("eve", "stalksTh3m")]
pub type StoreType {
Plain
External
Scram
}
pub type Caching(result) {
Cache(result)
Nocache(result)
}
pub fn user_exists(user: String,
_server: String) {
case list.key_find(credentials, user) {
Ok(_) -> Nocache(True)
Error(_) -> Nocache(False)
}
}
pub fn check_password(user: String,
_authz_id: String,
_host: String,
password: String) {
Nocache(list.contains(credentials, #(user, password)))
}
pub fn plain_password_required() { True }
pub fn store_type(_server: String) { External }
pub fn start(_host: String) { Nil }
pub fn stop(_host: String) { Nil }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment