diff --git a/core/core.go b/core/core.go index caa8df2..14f4b01 100644 --- a/core/core.go +++ b/core/core.go @@ -121,6 +121,19 @@ func validateAdmin(name, password string) error { return nil } +// validateName checks that the username and password pass the minimal +// validation check +func validateUser(name, password string) error { + if name == "" { + return errors.New("User name must not be blank") + } + if password == "" { + return errors.New("Password must be at least one character") + } + + return nil +} + // Init reads the records from disk from a given path func Init(path string) (err error) { if err = passvault.InitFromDisk(path); err != nil { @@ -140,6 +153,11 @@ func Create(jsonIn []byte) ([]byte, error) { return jsonStatusError(errors.New("Vault is already created")) } + // Validate the Name and Password as valid + if err := validateUser(s.Name, s.Password); err != nil { + return jsonStatusError(err) + } + if _, err := passvault.AddNewRecord(s.Name, s.Password, true); err != nil { log.Printf("Error adding record for %s: %s\n", s.Name, err) return jsonStatusError(err) @@ -180,6 +198,11 @@ func Delegate(jsonIn []byte) ([]byte, error) { return jsonStatusError(errors.New("Vault is not created yet")) } + // Validate the Name and Password as valid + if err := validateUser(s.Name, s.Password); err != nil { + return jsonStatusError(err) + } + // Find password record for user and verify that their password // matches. If not found then add a new entry for this user.