The clean & modern RSS server that doesn't give you any crap. https://thearsse.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.0 KiB

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\REST\Fever;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\ExceptionInput;
class User {
public static function register(string $user, string $password = null): string {
$password = $password ?? Arsse::$user->generatePassword();
$hash = md5("$user:$password");
$tr = Arsse::$db->begin();
Arsse::$db->tokenRevoke($user, "fever.login");
Arsse::$db->tokenCreate($user, "fever.login", $hash);
$tr->commit();
return $password;
}
public static function unregister(string $user): bool {
return (bool) Arsse::$db->tokenRevoke($user, "fever.login");
}
public static function authenticate(string $user, string $password): bool {
try {
return (bool) Arsse::$db->tokenLookup("fever.login", md5("$user:$password"));
} catch (ExceptionInput $e) {
return false;
}
}
}