// Validates user data, if it is correct the user is inserted in the db func Register(user *models.User) (int, error) { user_id := 0 // Check if the user already exists if models.UserExists(user.Fields["username"]) { return user_id, errors.New("user-exists") } // The user's password is hashed user.Fields["password"] = getPasswordHash(user.Fields["password"]) // Insert the user in the database user_id = user.Insert() return user_id, nil }