Esempio n. 1
0
File: app.go Progetto: schmich/ward
func (app *App) openStore() *store.Store {
	for {
		master := readPassword("Master password: ")
		db, err := store.Open(app.storeFileName, master)
		if err == nil {
			return db
		}

		printError("%s\n", err)

		if _, ok := err.(crypto.IncorrectPasswordError); !ok {
			if _, ok = err.(crypto.InvalidPasswordError); !ok {
				os.Exit(1)
			}
		}
	}
}
Esempio n. 2
0
func (s *StoreSuite) TestUpdateMasterPassword(c *C) {
	fileName := tempFileName()
	db, _ := store.Create(fileName, "pass", 1)
	credentials := make(map[string]*store.Credential, 100)
	for i := 0; i < 100; i++ {
		login := strconv.Itoa(i)
		credentials[login] = &store.Credential{
			Login:    login,
			Password: "bar",
			Realm:    "baz",
			Note:     "quux",
		}
		db.AddCredential(credentials[login])
	}
	c.Assert(len(db.AllCredentials()), Equals, len(credentials))
	db.UpdateMasterPassword("newpass", 100)
	db.Close()
	db, _ = store.Open(fileName, "newpass")
	newCredentials := db.AllCredentials()
	c.Assert(len(newCredentials), Equals, len(credentials))
	for _, credential := range newCredentials {
		assertCredentialsEqual(c, credential, credentials[credential.Login])
	}
}