2024-01-05 14:41:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CreateUser(login string, password interop.Hash256) {
|
|
|
|
ctx := storage.GetContext()
|
2024-01-12 14:31:25 +00:00
|
|
|
storedValue := storage.Get(ctx, login).(interop.Hash256)
|
|
|
|
if storedValue != nil {
|
|
|
|
panic("This user already exists")
|
|
|
|
} else {
|
|
|
|
storage.Put(ctx, login, password)
|
|
|
|
}
|
2024-01-05 14:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func CheckUser(login string, givenPassword interop.Hash256) {
|
2024-01-13 18:44:49 +00:00
|
|
|
password := GetUser(login)
|
|
|
|
if !password.Equals(givenPassword) {
|
|
|
|
panic("Password hashes does not match")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUser(login string) interop.Hash256 {
|
2024-01-05 14:41:00 +00:00
|
|
|
ctx := storage.GetReadOnlyContext()
|
|
|
|
password := storage.Get(ctx, login).(interop.Hash256)
|
|
|
|
if password == nil {
|
2024-01-13 18:44:49 +00:00
|
|
|
panic("The user does not exist")
|
2024-01-05 14:41:00 +00:00
|
|
|
}
|
2024-01-13 18:44:49 +00:00
|
|
|
return password
|
2024-01-05 14:41:00 +00:00
|
|
|
}
|
2024-01-12 14:27:21 +00:00
|
|
|
|
|
|
|
func DeleteUser(login string) {
|
|
|
|
ctx := storage.GetContext()
|
|
|
|
storage.Delete(ctx, login)
|
|
|
|
}
|
2024-01-12 14:32:39 +00:00
|
|
|
|
|
|
|
func UpdateUser(login string, password interop.Hash256) {
|
|
|
|
ctx := storage.GetContext()
|
|
|
|
storedValue := storage.Get(ctx, login).(interop.Hash256)
|
|
|
|
if storedValue == nil {
|
|
|
|
panic("This user does not exist")
|
|
|
|
} else {
|
|
|
|
storage.Put(ctx, login, password)
|
|
|
|
}
|
|
|
|
}
|