Documentation ¶
Overview ¶
passwd file library for web applications Copyright (c) 2016 aerth import github.com/aerth/passwd MIT License
Example ¶
package main import ( "fmt" "log" "math/rand" "strconv" "time" "github.com/aerth/passwd" ) var a []int var c chan int var cb chan bool var c1, c2, c3, c4 chan int var i1, i2 int var b bool var err error var r *rand.Rand func init() { r = rand.New(rand.NewSource(time.Now().UnixNano())) } func dummy() { user := strconv.FormatUint(uint64(r.Uint32()), 10) user2 := strconv.FormatUint(uint64(r.Uint32()), 10) err = passwd.Insert(user+user2, []byte("password")) if err != nil { fmt.Println("Dummy Insert Error: ", err) log.Println("Created Dummy:", user+user2) } else { e := passwd.Write() if e != nil { fmt.Println("Didn't create dummy:", e) } else { log.Println("Created Dummy:", user+user2) } } } func main() { passwd.Parse() dummy() dummy() dummy() b = passwd.Match("root", []byte("pasksword")) fmt.Println("Match:", b) b = passwd.Match("root", []byte("password")) fmt.Println("Match:", b) err = passwd.Update("root", []byte("pasksword")) if err != nil { fmt.Println("Insert Error: ", err) } else { passwd.Write() } b = passwd.Match("root", []byte("pasksword")) fmt.Println("Match:", b) b = passwd.Match("root", []byte("password")) fmt.Println("Match:", b) // err = passwd.Delete("root") // if err != nil { // fmt.Println("Delete Error: ", err) // } else { // passwd.Write() // } // b = passwd.Match("root", []byte("pasksword")) // fmt.Println("Match:", b) // b = passwd.Match("root", []byte("password")) // fmt.Println("Match:", b) for { } } func sleep(n int64) { time.Sleep(time.Second * 1) }
Output:
Index ¶
- func Delete(user string) error
- func Insert(user string, password []byte) error
- func InsertOrUpdate(user string, password []byte)
- func List() []string
- func Match(user string, password []byte) bool
- func Parse()
- func SetLocation(loc string)
- func Update(user string, password []byte) error
- func UpdateID(old, new string, p []byte) error
- func Write() error
- type PasswdFile
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Insert ¶
Insert returns an error if the user exists already. Otherwise, it inserts the user and hashed password into the usertable. Write() must be called to make actual changes to the passwd file.
func InsertOrUpdate ¶
InsertOrUpdate returns no error.
func SetLocation ¶
func SetLocation(loc string)
Types ¶
type PasswdFile ¶
type PasswdFile struct {
// contains filtered or unexported fields
}
func New ¶
func New(loc string, key ...[]byte) *PasswdFile
Click to show internal directories.
Click to hide internal directories.