Skip to content

Commit 5bb1ab2

Browse files
committed
ensured usernames and passwords are case insensitive by enforcing lower case
1 parent d5807c1 commit 5bb1ab2

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

Sources/LocalAuthentication/Routing/jsonroutes/JSONHandlers.login.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension LocalAuthJSONHandlers {
4242
if let postBody = request.postBodyString, !postBody.isEmpty {
4343
do {
4444
let postBodyJSON = try postBody.jsonDecode() as? [String: String] ?? [String: String]()
45-
if let u = postBodyJSON["username"], !u.isEmpty,
45+
if let u = postBodyJSON["username"]?.lowercased(), !u.isEmpty,
4646
let p = postBodyJSON["password"], !p.isEmpty {
4747

4848
do{

Sources/LocalAuthentication/Routing/jsonroutes/JSONHandlers.register.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ extension LocalAuthJSONHandlers {
2828
if let postBody = request.postBodyString, !postBody.isEmpty {
2929
do {
3030
let postBodyJSON = try postBody.jsonDecode() as? [String: String] ?? [String: String]()
31-
if let u = postBodyJSON["username"], !u.isEmpty,
32-
let e = postBodyJSON["email"], !e.isEmpty {
31+
if let u = postBodyJSON["username"]?.lowercased(), !u.isEmpty,
32+
let e = postBodyJSON["email"]?.lowercased(), !e.isEmpty {
3333
let err = Account.register(u, e, .provisional, baseURL: AuthenticationVariables.baseURL)
3434
if err != .noError {
3535
LocalAuthHandlers.error(request, response, error: "Registration Error: \(err)", code: .badRequest)

Sources/LocalAuthentication/Routing/webroutes/WebHandlers.login.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension LocalAuthWebHandlers {
2323
var context: [String : Any] = ["title": "Perfect Authentication Server"]
2424
context["csrfToken"] = request.session?.data["csrf"] as? String ?? ""
2525

26-
if let u = request.param(name: "username"), !(u as String).isEmpty,
26+
if let u = request.param(name: "username")?.lowercased(), !(u as String).isEmpty,
2727
let p = request.param(name: "password"), !(p as String).isEmpty {
2828
do {
2929
let acc = try Account.login(u, p)

Sources/LocalAuthentication/Routing/webroutes/WebHandlers.register.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ extension LocalAuthWebHandlers {
3535
if let i = request.session?.userid, !i.isEmpty { response.redirect(path: "/") }
3636
var context: [String : Any] = ["title": "Perfect Authentication Server"]
3737

38-
if let u = request.param(name: "username"), !(u as String).isEmpty,
39-
let e = request.param(name: "email"), !(e as String).isEmpty {
38+
if let u = request.param(name: "username")?.lowercased(), !(u as String).isEmpty,
39+
let e = request.param(name: "email")?.lowercased(), !(e as String).isEmpty {
4040
let err = Account.register(u, e, .provisional, baseURL: AuthenticationVariables.baseURL)
4141
if err != .noError {
4242
print(err)

0 commit comments

Comments
 (0)