Anonymous user
SQL-based authentication: Difference between revisions
→{{header|Tcl}}: Got rid of the external md5 requirement by "borrowing" SQL statements from the Perl version
(→Tcl: Added implementation) |
(→{{header|Tcl}}: Got rid of the external md5 requirement by "borrowing" SQL statements from the Perl version) |
||
Line 91:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
Also requires the TDBC driver for MySQL
<lang Tcl>package require tdbc
package require
Line 102:
}
# A simple helper to keep code shorter
proc r64k {} {
expr int(65536*rand())
}
Line 112 ⟶ 110:
set salt [binary format ssssssss \
[r64k] [r64k] [r64k] [r64k] [r64k] [r64k] [r64k] [r64k]]
# They are bound automatically to local variables with the same name
$handle allrows {
INSERT IGNORE INTO users (username, pass_salt, pass_md5)
VALUES (:user, :salt,
}
return ;# Ignore the result of the allrows method
Line 122 ⟶ 121:
proc authenticate_user {handle user pass} {
$handle foreach row {
SELECT userid
username=:user
} {
return [dict
}
# Only get here if no rows selected
error "authentication failed for user \"$user\""
}</lang>
|