sqlCreateAuthenticationLogsTable:fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (username VARCHAR(100), successful BOOL, time INTEGER)",authenticationLogsTableName),
sqlCreateAuthenticationLogsUserTimeIndex:fmt.Sprintf("CREATE INDEX IF NOT EXISTS usr_time_idx ON %s (username, time)",authenticationLogsTableName),
sqlUpsertSecondFactorPreference:fmt.Sprintf("INSERT INTO %s (username, second_factor_method) VALUES ($1, $2) ON CONFLICT (username) DO UPDATE SET second_factor_method=$2",preferencesTableName),
sqlTestIdentityVerificationTokenExistence:fmt.Sprintf("SELECT EXISTS (SELECT * FROM %s WHERE token=$1)",identityVerificationTokensTableName),
sqlInsertIdentityVerificationToken:fmt.Sprintf("INSERT INTO %s (token) VALUES ($1)",identityVerificationTokensTableName),
sqlDeleteIdentityVerificationToken:fmt.Sprintf("DELETE FROM %s WHERE token=$1",identityVerificationTokensTableName),
sqlGetTOTPSecretByUsername:fmt.Sprintf("SELECT secret FROM %s WHERE username=$1",totpSecretsTableName),
sqlUpsertTOTPSecret:fmt.Sprintf("INSERT INTO %s (username, secret) VALUES ($1, $2) ON CONFLICT (username) DO UPDATE SET secret=$2",totpSecretsTableName),
sqlGetU2FDeviceHandleByUsername:fmt.Sprintf("SELECT keyHandle, publicKey FROM %s WHERE username=$1",u2fDeviceHandlesTableName),
sqlUpsertU2FDeviceHandle:fmt.Sprintf("INSERT INTO %s (username, keyHandle, publicKey) VALUES ($1, $2, $3) ON CONFLICT (username) DO UPDATE SET keyHandle=$2, publicKey=$3",u2fDeviceHandlesTableName),
sqlInsertAuthenticationLog:fmt.Sprintf("INSERT INTO %s (username, successful, time) VALUES ($1, $2, $3)",authenticationLogsTableName),
sqlGetLatestAuthenticationLogs:fmt.Sprintf("SELECT successful, time FROM %s WHERE time>$1 AND username=$2 ORDER BY time DESC",authenticationLogsTableName),
},
}
iferr:=provider.initialize(db);err!=nil{
logging.Logger().Fatalf("Unable to initialize SQL database: %v",err)