getgrav/grav · error · RuntimeException
User account with this username already exists
Error message
User account with this username already exists
What it means
Error "User account with this username already exists" thrown in getgrav/grav.
Source
Thrown at system/src/Grav/Common/Flex/Types/Users/UserObject.php:615
public function save()
{
// TODO: We may want to handle this in the storage layer in the future.
$key = $this->getStorageKey();
// `@@` is Flex's marker for an in-memory (not-yet-persisted) storage key.
// `str_contains` is the correct predicate here — `strpos` returns 0 when
// the marker is at position 0 (e.g. `@@hash`), which is falsy and would
// have skipped the uniqueness check below.
$isNewUser = $key === '' || str_contains($key, '@@');
if ($isNewUser) {
$newKey = $this->getKey();
// Prevent overwriting an existing account when a low-privileged user
// creates a new user with an already-taken username (GHSA-rr73-568v-28f8).
// Applies to every storage implementation, not just FileStorage.
$storage = $this->getFlexDirectory()->getStorage();
if ($storage->hasKey($newKey)) {
throw new RuntimeException('User account with this username already exists');
}
$this->setStorageKey($newKey);
}
$password = $this->getProperty('password') ?? $this->getProperty('password1');
if (null !== $password && '' !== $password) {
$password2 = $this->getProperty('password2');
if (!\is_string($password) || ($password2 && $password !== $password2)) {
throw new \RuntimeException('Passwords did not match.');
}
$this->setProperty('hashed_password', Authentication::create($password));
}
$this->unsetProperty('password');
$this->unsetProperty('password1');
$this->unsetProperty('password2');
View on GitHub (pinned to 6040efed04)
When it happens
Trigger: Thrown at system/src/Grav/Common/Flex/Types/Users/UserObject.php:615 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of getgrav/grav@6040efed04 (2026-08-17).
Data as JSON: /api/errors/144ab5eb5824f014.
Report an issue: GitHub.