summaryrefslogtreecommitdiff
path: root/persistence.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-20 19:27:22 +0200
committerxengineering <me@xengineering.eu>2023-05-20 19:27:22 +0200
commit1a920930fe71e569eee124259b43db8e43af3c76 (patch)
treeac80fab1011e3740617396ab73edce5dd084902a /persistence.go
parent6713c3cc833906802acf3ef89e5ac3dd7f69e128 (diff)
downloadlimox-1a920930fe71e569eee124259b43db8e43af3c76.tar
limox-1a920930fe71e569eee124259b43db8e43af3c76.tar.zst
limox-1a920930fe71e569eee124259b43db8e43af3c76.zip
Implement last password persistence
Diffstat (limited to 'persistence.go')
-rw-r--r--persistence.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/persistence.go b/persistence.go
index 5199fc5..bc6eee4 100644
--- a/persistence.go
+++ b/persistence.go
@@ -6,9 +6,16 @@ import (
"path/filepath"
)
+type persistentString uint8
+
+const (
+ Jid persistentString = iota
+)
+
const (
RelDataPath = `/.config/limox`
RelJidPath = `/last_jid.txt`
+ RelPwdPath = `/last_pwd.txt`
)
func setLastJid(j string) {
@@ -38,6 +45,33 @@ func getLastJid() string {
return string(content)
}
+func setLastPwd(p string) {
+ data, err := assertDatadir()
+ if err != nil {
+ return
+ }
+
+ path := filepath.Join(data, RelPwdPath)
+
+ _ = ioutil.WriteFile(path, []byte(p), 0600)
+}
+
+func getLastPwd() string {
+ data, err := assertDatadir()
+ if err != nil {
+ return ""
+ }
+
+ path := filepath.Join(data, RelPwdPath)
+
+ content, err := ioutil.ReadFile(path)
+ if err != nil {
+ return ""
+ }
+
+ return string(content)
+}
+
func assertDatadir() (string, error) {
home, err := os.UserHomeDir()
if err != nil {