Skip to content

Commit 782f35a

Browse files
committed
Allow optional password to support Windows/Integrated Authentication
1 parent d432643 commit 782f35a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Sources/SQLClientSwift/SQLClient.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public enum SQLClientEncryption: String, Sendable {
8383
public struct SQLClientConnectionOptions: Sendable {
8484
public var server: String
8585
public var username: String
86-
public var password: String
86+
public var password: String?
8787
public var database: String?
8888
public var domain: String?
8989
public var port: UInt16?
@@ -95,7 +95,7 @@ public struct SQLClientConnectionOptions: Sendable {
9595
public var queryTimeout: Int = 0
9696
public var loginTimeout: Int = 0
9797

98-
public init(server: String, username: String, password: String, database: String? = nil, domain: String? = nil) {
98+
public init(server: String, username: String, password: String? = nil, database: String? = nil, domain: String? = nil) {
9999
self.server = server
100100
self.username = username
101101
self.password = password
@@ -191,7 +191,7 @@ public actor SQLClient {
191191
private var connection: OpaquePointer?
192192
private var connected = false
193193

194-
public func connect(server: String, username: String, password: String, database: String? = nil, domain: String? = nil) async throws {
194+
public func connect(server: String, username: String, password: String? = nil, database: String? = nil, domain: String? = nil) async throws {
195195
try await connect(options: SQLClientConnectionOptions(server: server, username: username, password: password, database: database, domain: domain))
196196
}
197197

@@ -322,7 +322,9 @@ public actor SQLClient {
322322

323323
if SQLClient.debugEnabled { print("DEBUG: _connectSync - setting login options") }
324324
dbsetlname(lgn, options.username, 2) // DBSETUSER
325-
dbsetlname(lgn, options.password, 3) // DBSETPWD
325+
if let password = options.password {
326+
dbsetlname(lgn, password, 3) // DBSETPWD
327+
}
326328
dbsetlname(lgn, "SQLClientSwift", 5) // DBSETAPP
327329

328330
// Ensure we get UTF-8 from the server for N-types

0 commit comments

Comments
 (0)