From 1a920930fe71e569eee124259b43db8e43af3c76 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 20 May 2023 19:27:22 +0200 Subject: Implement last password persistence --- persistence.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'persistence.go') 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 { -- cgit v1.2.3-70-g09d2