2019-11-16 19:50:58 +00:00
|
|
|
package storage
|
|
|
|
|
2020-03-04 23:25:52 +00:00
|
|
|
import "fmt"
|
|
|
|
|
2019-12-07 23:22:02 +00:00
|
|
|
// Keep table names in lower case because some DB does not support upper case.
|
|
|
|
var preferencesTableName = "user_preferences"
|
|
|
|
var identityVerificationTokensTableName = "identity_verification_tokens"
|
|
|
|
var totpSecretsTableName = "totp_secrets"
|
|
|
|
var u2fDeviceHandlesTableName = "u2f_devices"
|
|
|
|
var authenticationLogsTableName = "authentication_logs"
|
2020-03-04 23:25:52 +00:00
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// SQLCreateUserPreferencesTable common SQL query to create user_preferences table.
|
2020-03-04 23:25:52 +00:00
|
|
|
var SQLCreateUserPreferencesTable = fmt.Sprintf(`
|
|
|
|
CREATE TABLE IF NOT EXISTS %s (
|
|
|
|
username VARCHAR(100) PRIMARY KEY,
|
|
|
|
second_factor_method VARCHAR(11)
|
|
|
|
)`, preferencesTableName)
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// SQLCreateIdentityVerificationTokensTable common SQL query to create identity_verification_tokens table.
|
2020-03-04 23:25:52 +00:00
|
|
|
var SQLCreateIdentityVerificationTokensTable = fmt.Sprintf(`
|
|
|
|
CREATE TABLE IF NOT EXISTS %s (token VARCHAR(512))
|
|
|
|
`, identityVerificationTokensTableName)
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// SQLCreateTOTPSecretsTable common SQL query to create totp_secrets table.
|
2020-03-04 23:25:52 +00:00
|
|
|
var SQLCreateTOTPSecretsTable = fmt.Sprintf(`
|
|
|
|
CREATE TABLE IF NOT EXISTS %s (username VARCHAR(100) PRIMARY KEY, secret VARCHAR(64))
|
|
|
|
`, totpSecretsTableName)
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// SQLCreateU2FDeviceHandlesTable common SQL query to create u2f_device_handles table.
|
2020-03-04 23:25:52 +00:00
|
|
|
var SQLCreateU2FDeviceHandlesTable = fmt.Sprintf(`
|
|
|
|
CREATE TABLE IF NOT EXISTS %s (
|
|
|
|
username VARCHAR(100) PRIMARY KEY,
|
|
|
|
keyHandle TEXT,
|
|
|
|
publicKey TEXT
|
|
|
|
)`, u2fDeviceHandlesTableName)
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// SQLCreateAuthenticationLogsTable common SQL query to create authentication_logs table.
|
2020-03-04 23:25:52 +00:00
|
|
|
var SQLCreateAuthenticationLogsTable = fmt.Sprintf(`
|
|
|
|
CREATE TABLE IF NOT EXISTS %s (
|
|
|
|
username VARCHAR(100),
|
|
|
|
successful BOOL,
|
|
|
|
time INTEGER,
|
|
|
|
INDEX usr_time_idx (username, time)
|
|
|
|
)`, authenticationLogsTableName)
|