summaryrefslogtreecommitdiff
path: root/src/parabola_hackers/password.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/parabola_hackers/password.go')
-rw-r--r--src/parabola_hackers/password.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/parabola_hackers/password.go b/src/parabola_hackers/password.go
new file mode 100644
index 0000000..4ea345f
--- /dev/null
+++ b/src/parabola_hackers/password.go
@@ -0,0 +1,63 @@
+// Copyright 2015-2016 Luke Shumaker <lukeshu@sbcglobal.net>.
+//
+// This is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+
+package parabola_hackers
+
+import (
+ "io/ioutil"
+ "lukeshu.com/git/go/libgnulinux.git/crypt"
+ "fmt"
+ "os"
+ "strings"
+)
+
+/* Note that the password hash value should be one of:
+ <empty> - no password set, allow login without password
+ ! - used to prevent logins
+ x - "valid" encrypted password that does not match any valid password
+ often used to indicate that the password is defined elsewhere
+ other - encrypted password, in crypt(3) format */
+
+func LoadUserPassword(filename string) (hash string, err error) {
+ file, err := os.Open(filename)
+ if err != nil {
+ return
+ }
+ contents, err := ioutil.ReadAll(file)
+ if err != nil {
+ return
+ }
+ lines := strings.Split(string(contents), "\n")
+ switch len(lines) {
+ case 1:
+ hash = lines[0]
+ case 2:
+ if lines[1] == "" {
+ hash = lines[0]
+ } else {
+ err = fmt.Errorf("Invalid password format in file: %q", filename)
+ }
+ default:
+ err = fmt.Errorf("Invalid password format in file (number of lines): %q", filename)
+ return
+ }
+ if hash != "!" && !crypt.SaltOk(hash) {
+ hash = "!"
+ err = fmt.Errorf("Invalid password format in file (invalid salt): %q", filename)
+ return
+ }
+ return
+}