Пример #1
0
// Changes a user's password to the given string.
func (user *User) SetPassword(password string) {
	if password == "" {
		user.PasswordHash = nil
	} else {
		user.PasswordHash = passwordhash.New(password)
	}
}
Пример #2
0
// Changes a user's password to the given string.
func (user *userImpl) SetPassword(password string) {
	if password == "" {
		user.PasswordHash_ = nil
	} else {
		user.PasswordHash_ = passwordhash.New(password)
	}
}
Пример #3
0
func add(r *http.Request) (uint64, error) {
	// get an id
	id, err := NoeqClient.GenOne()
	if err != nil {
		return 0, err
	}
	username := r.FormValue("username")
	password := r.FormValue("password")
	confirm := r.FormValue("confirm_password")
	email := r.FormValue("email")
	if username == "" || password == "" || confirm == "" || password != confirm || email == "" {
		return 0, fmt.Errorf("invalid registration details")
	}

	// try to set it
	res, rerr := RedisClient.Setnx("users:"+username, id)
	if rerr != nil {
		return 0, rerr
	} else if !res {
		// someone beat us to it
		return 0, fmt.Errorf("username already exists")
	}

	// set the discussion record
	ph := passwordhash.New(password)
	var userData = make(map[string]string)
	userData[fmt.Sprintf("user:%d:username", id)] = username
	userData[fmt.Sprintf("user:%d:password", id)] = string(ph.Hash)
	userData[fmt.Sprintf("user:%d:salt", id)] = string(ph.Salt)
	userData[fmt.Sprintf("user:%d:email", id)] = email
	rerr = RedisClient.Mset(userData)
	if rerr != nil {
		// roll it back
		return 0, rerr
	}
	return id, nil
}