func (s *IdentityService) UpsertPassword(user string,
	password []byte) (hotpURL string, hotpQR []byte, err error) {

	if err := services.VerifyPassword(password); err != nil {
		return "", nil, err
	}
	hash, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}

	otp, err := hotp.GenerateHOTP(defaults.HOTPTokenDigits, false)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}
	hotpQR, err = otp.QR(user)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}
	hotpURL = otp.URL(user)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}

	err = s.UpsertPasswordHash(user, hash)
	if err != nil {
		return "", nil, err
	}
	err = s.UpsertHOTP(user, otp)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}

	return hotpURL, hotpQR, nil

}
// UpsertPassword upserts new password and HOTP token
UpsertPassword upserts new password and HOTP token
// UpsertPassword upserts new password and HOTP token
func (s *IdentityService) UpsertPassword(user string,
	password []byte) (hotpURL string, hotpQR []byte, err error) {
	if err := services.VerifyPassword(password); err != nil {
		return "", nil, err
	}
	hash, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}
	otp, err := hotp.GenerateHOTP(defaults.HOTPTokenDigits, false)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}
	hotpQR, err = otp.QR(user)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}
	hotpURL = otp.URL(user)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}
	err = s.UpsertPasswordHash(user, hash)
	if err != nil {
		return "", nil, err
	}
	err = s.UpsertHOTP(user, otp)
	if err != nil {
		return "", nil, trace.Wrap(err)
	}
	return hotpURL, hotpQR, nil
}
func ( s * IdentityService ) UpsertPassword ( user string , password [ ] byte ) ( hotpURL string , hotpQR [ ] byte , err error ) { if err := services . VerifyPassword ( password ) ; err != nil { return " " , nil , err } hash , err := bcrypt . GenerateFromPassword ( password , bcrypt . DefaultCost ) if err != nil { return " " , nil , trace . Wrap ( err ) } otp , err := hotp . GenerateHOTP ( defaults . HOTPTokenDigits , false ) if err != nil { return " " , nil , trace . Wrap ( err ) } hotpQR , err = otp . QR ( user ) if err != nil { return " " , nil , trace . Wrap ( err ) } hotpURL = otp . URL ( user ) if err != nil { return " " , nil , trace . Wrap ( err ) } err = s . UpsertPasswordHash ( user , hash ) if err != nil { return " " , nil , err } err = s . UpsertHOTP ( user , otp ) if err != nil { return " " , nil , trace . Wrap ( err ) } return hotpURL , hotpQR , nil }
UpsertPassword upserts new password and HOTP token
UpsertPassword upserts new password and HOTP token