// Copyright 2015-2016 Luke Shumaker . // // 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 // . package parabola_hackers import ( "fmt" "io/ioutil" "os" "strings" "lukeshu.com/git/go/libgnulinux.git/crypt" ) /* Note that the password hash value should be one of: - 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 }