Skip to content

Commit d42692a

Browse files
committed
Added SqlCheckToken function
1 parent 2b37bb6 commit d42692a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sqlqueries.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,26 @@ func SqlGetToken(db *sql.DB, username string) (allowGetToken bool, tokenString s
192192
}
193193
}
194194
}
195+
196+
//Checks if the given token is in the database.
197+
func SqlCheckToken(db *sql.DB, inputToken string) (allowCheckToken bool) {
198+
//SELECTS Token FROM users table for the token and returns the token.
199+
checkTokenQuery := "SELECT Token FROM `users` WHERE Token = ?"
200+
token, err := db.Query(checkTokenQuery, inputToken)
201+
defer token.Close()
202+
if err != nil {
203+
return false
204+
} else {
205+
token.Next()
206+
207+
var tokenString string
208+
token.Scan(&tokenString)
209+
210+
if tokenString == "" {
211+
return false
212+
} else {
213+
return true
214+
}
215+
}
216+
217+
}

0 commit comments

Comments
 (0)