examples: check array length before access (#21641)

This commit is contained in:
Juan de Bruin 2024-06-04 17:38:06 +02:00 committed by GitHub
parent 1e86e06eb6
commit 096226bf05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,6 +37,9 @@ fn (mut app App) service_auth(username string, password string) !string {
users := sql db {
select from User where username == username
}!
if users.len == 0 {
return error('user not found')
}
user := users.first()
if user.username != username {
return error('user not found')