func (s *IdentityService) IncreaseLoginAttempts(user string) error {
	bucket := []string{"web", "users", user}

	data, _, err := s.backend.GetValAndTTL(bucket, "lock")
	// unexpected error?
	if err != nil && !trace.IsNotFound(err) {
		return trace.Wrap(err)
	}
	// bump the attempt count
	if len(data) < 1 {
		data = []byte{0}
	}
	// check the attempt count
	if len(data) > 0 && data[0] >= s.lockAfter {
		return trace.AccessDenied("this account has been locked for %v", s.lockDuration)
	}
	newData := []byte{data[0] + 1}
	// "create val" will create a new login attempt counter, or it will
	// do nothing if it's already there.
	//
	// "compare and swap" will bump the counter +1
	s.backend.CreateVal(bucket, "lock", data, s.lockDuration)
	_, err = s.backend.CompareAndSwap(bucket, "lock", newData, s.lockDuration, data)
	return trace.Wrap(err)
}
// IncreaseLoginAttempts bumps "login attempt" counter for the given user. If the counter
// reaches 'lockAfter' value, it locks the account and returns access denied error.
IncreaseLoginAttempts bumps "login attempt" counter for the given user. If the counter
reaches 'lockAfter' value, it locks the account and returns access denied error.
// IncreaseLoginAttempts bumps " login attempt " counter for the given user . If the counter // reaches ' lockAfter ' value it locks the account and returns access denied error .
func (s *IdentityService) IncreaseLoginAttempts(user string) error {
	bucket := []string{"web", "users", user}
	data, _, err := s.backend.GetValAndTTL(bucket, "lock")
	if err != nil && !trace.IsNotFound(err) {
		return trace.Wrap(err)
	}
	if len(data) < 1 {
		data = []byte{0}
	}
	if len(data) > 0 && data[0] >= s.lockAfter {
		return trace.AccessDenied("this account has been locked for %v", s.lockDuration)
	}
	newData := []byte{data[0] + 1}
	 "compare and swap" will bump the counter +1
	s.backend.CreateVal(bucket, "lock", data, s.lockDuration)
	_, err = s.backend.CompareAndSwap(bucket, "lock", newData, s.lockDuration, data)
	return trace.Wrap(err)
}
func ( s * IdentityService ) IncreaseLoginAttempts ( user string ) error { bucket := [ ] string { " " , " " , user } data , _ , err := s . backend . GetValAndTTL ( bucket , " " ) if err != nil && ! trace . IsNotFound ( err ) { return trace . Wrap ( err ) } if len ( data ) < 1 { data = [ ] byte { 0 } } if len ( data ) > 0 && data [ 0 ] >= s . lockAfter { return trace . AccessDenied ( " " , s . lockDuration ) } newData := [ ] byte { data [ 0 ] + 1 } s . backend . CreateVal ( bucket , " " , data , s . lockDuration ) _ , err = s . backend . CompareAndSwap ( bucket , " " , newData , s . lockDuration , data ) return trace . Wrap ( err ) }
IncreaseLoginAttempts bumps "login attempt" counter for the given user.
IncreaseLoginAttempts bumps " login attempt " counter for the given user .
// unexpected error? // bump the attempt count // check the attempt count // "create val" will create a new login attempt counter, or it will // do nothing if it's already there. // // "compare and swap" will bump the counter +1