5.3 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:25:44.390617+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | e2da1167bdd7ae60 |
User
Documentation: DbAPI.User.User Class
1. Purpose
This module provides a concrete, internal implementation of the IUserDbRecord interface (which itself implements IUser) for representing user records retrieved from the database. It encapsulates user data fields (e.g., ID, credentials, role, metadata) and exposes a static factory method (GetUser) to fetch a user record by username via stored procedures. Its role is to act as a data carrier between the database layer and higher-level authentication or user management logic, ensuring structured access to user information while abstracting SQL interaction details.
2. Public Interface
Note: The class is internal, so its members are not part of the public API surface of the DbAPI.User namespace, but they are documented per requirements.
-
UserConstructorinternal User(int id, string user, string display, string pwd, short role, DateTime lastModified, string lastModifiedBy, bool local)Initializes a new
Userinstance with all required field values. Parameters map directly to the public properties. -
GetUserStatic Methodinternal static ulong GetUser(IConnectionDetails connection, out IUserDbRecord usr, string userName)Retrieves a user record from the database by
userName. Executes two stored procedures sequentially:sp_UsersGetIdto resolve the user ID from the username (output parameter@UserId).sp_UsersGetto fetch full user details using the resolved ID.
On success, populatesusrwith a newUserinstance and returnsERROR_SUCCESS(0). On failure, returns an error code (e.g.,ERROR_LOGINFAILED,ERROR_ACCESS_DENIED,ERROR_UNKNOWN) and setsusrtonull.
Properties of
usrare populated usingUtilityhelper methods (e.g.,Utility.GetInt,Utility.GetString, etc.), which handleDBNulland type conversion.
3. Invariants
IDmust be a positive integer (validated inGetUser:if (0 >= id) { return ERROR_LOGINFAILED; }).UserName,DisplayName,Password,LastModifiedBymust be non-null strings (assigned viaUtility.GetString, which likely returnsstring.EmptyonDBNull; source does not confirm null-safety, but assignment occurs unconditionally).LastModifieddefaults toDateTime.MinValueifDBNull(handled byUtility.GetDateTime(..., DateTime.MinValue)).Roleis ashort(no explicit range validation in code; assumed to be domain-constrained by application logic).LocalOnlyis a boolean (assigned viaUtility.GetBool, implying stricttrue/falsemapping).- Database connection is disposed after use (ensured by
finally { cmd.Connection.Dispose(); }). - Stored procedure names are fixed:
sp_UsersGetId(ID lookup),sp_UsersGet(full record fetch).
4. Dependencies
- Imports/Usings:
DbAPI.Connections→ ProvidesIConnectionDetails,ConnectionManager, andErrors.ErrorCodes.DTS.Common.Classes→ Likely containsUtility(used for type-safe data extraction).DTS.Common.Interface.Database→ DefinesIUserDbRecord(implemented byUser).System.Data,System.Data.SqlClient→ ForSqlDbType,CommandType,SqlParameter,IDataReader.
- External Dependencies:
- SQL Server database with stored procedures:
sp_UsersGetId(input:@UserName NVARCHAR(255), output:@UserId INT) andsp_UsersGet(input:@UserId INT). ConnectionManager.GetSqlCommandmust returnERROR_SUCCESSfor valid connections.
- SQL Server database with stored procedures:
- Depended Upon:
IUserDbRecordinterface (consumed by callers ofGetUser).- Likely used by authentication modules (e.g., login workflows) that require user record resolution.
5. Gotchas
- Password stored in plaintext: The
Passwordproperty is directly assigned from the database (var password = Utility.GetString(reader, "password");). No hashing or encryption handling is evident—this may indicate legacy security practices. - Two-step database round-trips:
GetUserexecutes two stored procedures (ID lookup → full record fetch), which could be optimized into one query. reader.Close()before reusingcmd: TheSqlDataReaderis closed before resettingcmd.CommandTextand parameters. This is safe but non-idiomatic;usingblocks would improve robustness.- No validation of
userNameinput: Empty or nulluserNamemay cause unexpected behavior (e.g., SQL injection risk ifConnectionManagerdoes not sanitize parameters). ERROR_ACCESS_DENIEDreturned forGetSqlCommandfailure: This error code is misleading—it suggests authentication failure, but it may also indicate connection configuration issues.IUserDbRecordinterface is not defined here: Behavior ofIUser/IUserDbRecordmembers (e.g.,ID,UserName) is assumed from implementation but not verified in this file.Utilitymethods behavior is inferred: Assumptions aboutUtility.GetStringreturningstring.EmptyonDBNullare not confirmed by this source.
None identified from source alone.