{"record":{"id":"22c274e99425e540","repo":"TechnitiumSoftware/DnsServer","slug":"no-such-user-exists-username","errorCode":null,"errorMessage":"No such user exists: {username}","messagePattern":"No such user exists: (.+?)","errorType":"exception","errorClass":"DnsWebServiceException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Auth/AuthManager.cs","lineNumber":1177,"sourceCode":"\n            if (type == UserSessionType.ClusterApiToken)\n                throw new InvalidOperationException();\n\n            UserSession session = new UserSession(type, tokenName, user, remoteAddress, userAgent);\n\n            if (!_sessions.TryAdd(session.Token, session))\n                throw new DnsWebServiceException(\"Error while creating session. Please try again.\");\n\n            user.LoggedInFrom(remoteAddress);\n\n            return session;\n        }\n\n        public UserSession CreateSession(UserSessionType type, string tokenName, string username, IPAddress remoteAddress, string userAgent)\n        {\n            User user = GetUser(username);\n            if (user is null)\n                throw new DnsWebServiceException(\"No such user exists: \" + username);\n\n            return CreateSession(type, tokenName, user, remoteAddress, userAgent);\n        }\n\n        public UserSession CreateSession(UserSessionType type, string tokenName, User user, IPAddress remoteAddress, string userAgent)\n        {\n            if (user.Disabled)\n                throw new DnsWebServiceException(\"User account is disabled. Please contact your administrator.\");\n\n            UserSession session = new UserSession(type, tokenName, user, remoteAddress, userAgent);\n\n            if (!_sessions.TryAdd(session.Token, session))\n                throw new DnsWebServiceException(\"Error while creating session. Please try again.\");\n\n            user.LoggedInFrom(remoteAddress);\n\n            return session;\n        }","sourceCodeStart":1159,"sourceCodeEnd":1195,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Auth/AuthManager.cs#L1159-L1195","documentation":"Thrown by AuthManager.CreateSession (the username overload) when GetUser(username) returns null, i.e. the user store has no matching record. It is a DnsWebServiceException because it surfaces as a fault to the web service caller during login/token creation. The message echoes the offending username to make the mismatch obvious.","triggerScenarios":"Calling CreateSession(type, tokenName, username, remoteAddress, userAgent) where 'username' does not resolve to an existing User. This is the path the username-based login / token-creation endpoint takes before it can build a UserSession.","commonSituations":"Wrong/typo'd username at login; the user was deleted between auth checks and session creation; case mismatch (note usernames are normalized with ToLowerInvariant elsewhere, so a differently-cased lookup can miss); a restored config that references a user that no longer exists.","solutions":["Confirm the username exists in the users store (case-insensitively, since names are lowercased) before requesting a session.","Create the missing user account first, then retry CreateSession.","Check whether the user was recently deleted/disabled by an admin and restore it if appropriate."],"exampleFix":"// before\nvar session = authManager.CreateSession(type, tokenName, username, remoteAddress, userAgent);\n\n// after\nif (authManager.GetUser(username.ToLowerInvariant()) is null)\n    return Error($\"No such user exists: {username}\");\nvar session = authManager.CreateSession(type, tokenName, username, remoteAddress, userAgent);","handlingStrategy":"validation","validationCode":"// Resolve the user before requesting a session.\nstring normalized = username?.ToLowerInvariant()?.Trim();\nif (string.IsNullOrEmpty(normalized))\n    return BadRequest(\"Username required.\");\nif (authManager.GetUser(normalized) is null)\n    return NotFound($\"No such user exists: {username}\");\n// safe to create session now","typeGuard":null,"tryCatchPattern":"// Only if you cannot pre-validate (e.g. caller has no GetUser access):\ntry { var session = authManager.CreateSession(type, tokenName, username, remoteAddress, userAgent); }\ncatch (DnsWebServiceException ex) when (ex.Message.StartsWith(\"No such user exists\"))\n{ return NotFound(ex.Message); }","preventionTips":["Normalize the username with ToLowerInvariant before lookup, since names are stored lowercased.","Validate the user exists at the API boundary before delegating to CreateSession.","Re-resolve the user after long-running flows to avoid delete-during-login races."],"tags":["auth","session","login","user-management"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}