summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-03-16 13:54:06 +0530
committersinanmohd <sinan@sinanmohd.com>2024-03-16 13:54:06 +0530
commit1f3d9524ca64a07f419dd47840cdf84b32e9e857 (patch)
tree23382fda0d16e4985c3cdbdac445f5e96d7a4aae
parente5c9c56ec5fa243206f65ff77bd0f10708a284a3 (diff)
db/Account: PassHash -> Password
-rw-r--r--cmd/redqctl/main.go2
-rw-r--r--db/account.go22
-rw-r--r--db/main.go2
3 files changed, 13 insertions, 13 deletions
diff --git a/cmd/redqctl/main.go b/cmd/redqctl/main.go
index e60ea85..ce77f77 100644
--- a/cmd/redqctl/main.go
+++ b/cmd/redqctl/main.go
@@ -38,7 +38,7 @@ func create(args []string, db *redqdb.SafeDB) {
"The first name to associate with the account")
f.StringVar(&ac.Info.LastName, "lname", "",
"The last name to associate with the account")
- f.StringVar(&ac.PassHash, "pass", "",
+ f.StringVar(&ac.Password, "pass", "",
"The password to associate with the account")
f.UintVar(&ac.Info.Level, "level", 0,
"The level to associate with the account")
diff --git a/db/account.go b/db/account.go
index 507060e..6bf4239 100644
--- a/db/account.go
+++ b/db/account.go
@@ -8,7 +8,7 @@ import (
type Account struct {
UserName string `validate:"required,alphanum,max=64"`
- PassHash string `json:",omitempty" validate:"required,min=10,max=128"`
+ Password string `json:",omitempty" validate:"required,min=10,max=128"`
Info *Login
}
@@ -25,7 +25,7 @@ func (ac *Account) CreateAccount(safe *SafeDB) error {
INSERT INTO Accounts (
id,
UserName,
- PassHash,
+ Password,
Level,
FirstName,
LastName
@@ -47,7 +47,7 @@ func (ac *Account) CreateAccount(safe *SafeDB) error {
_, err = safe.db.Exec(
sqlStatement,
ac.UserName,
- ToBlake3(ac.PassHash),
+ ToBlake3(ac.Password),
ac.Info.FirstName,
ac.Info.LastName,
@@ -59,13 +59,13 @@ func (ac *Account) CreateAccount(safe *SafeDB) error {
func (ac *Account) Login(safe *SafeDB) error {
const sqlStatementQuery string = `
- SELECT id, PassHash, Level, FirstName, LastName
+ SELECT id, Password, Level, FirstName, LastName
FROM Accounts
WHERE Accounts.UserName = ?
`
err := safe.validate.Struct(ac)
- fmt.Println(ac.PassHash, ac.UserName)
+ fmt.Println(ac.Password, ac.UserName)
if err != nil {
log.Println(err)
return err
@@ -77,10 +77,10 @@ func (ac *Account) Login(safe *SafeDB) error {
row := safe.db.QueryRow(sqlStatementQuery, ac.UserName)
safe.mu.Unlock()
- var PassHash string
+ var Password string
err = row.Scan(
&ac.Info.id,
- &PassHash,
+ &Password,
&ac.Info.FirstName,
&ac.Info.LastName,
&ac.Info.Level,
@@ -88,10 +88,10 @@ func (ac *Account) Login(safe *SafeDB) error {
if err != nil {
return err
}
- if PassHash != ToBlake3(ac.PassHash) {
+ if Password != ToBlake3(ac.Password) {
return errors.New("Auth failed")
}
- ac.PassHash = ""
+ ac.Password = ""
err = ac.Info.Bearer.Generate(safe, ac.Info)
if err != nil {
@@ -103,7 +103,7 @@ func (ac *Account) Login(safe *SafeDB) error {
func (ac *Account) fromBearer(safe *SafeDB, b *Bearer) error {
const sqlStatementAccount string = `
- SELECT UserName, PassHash, Level, FirstName, LastName
+ SELECT UserName, Password, Level, FirstName, LastName
FROM Accounts
WHERE Accounts.id = ?
`
@@ -117,7 +117,7 @@ func (ac *Account) fromBearer(safe *SafeDB, b *Bearer) error {
ac.Info.Bearer = b
err := row.Scan(
&ac.UserName,
- &ac.PassHash,
+ &ac.Password,
&ac.Info.FirstName,
&ac.Info.LastName,
diff --git a/db/main.go b/db/main.go
index fcfbf11..49658cd 100644
--- a/db/main.go
+++ b/db/main.go
@@ -36,7 +36,7 @@ func NewSafeDB() (*SafeDB, error) {
CREATE TABLE IF NOT EXISTS Accounts(
id INTEGER PRIMARY KEY,
UserName CHAR(64) NOT NULL UNIQUE,
- PassHash CHAR(128) NOT NULL,
+ Password CHAR(128) NOT NULL,
Level INTEGER NOT NULL,
FirstName CHAR(32) NOT NULL,