public bool CreateKeys(int customerId) { if (customerId != 0) { var hmac = new HmacAuthentication(); var userData = WebApiCaching.UserData(); string key1, key2; for (int i = 0; i < 9999; ++i) { if (hmac.CreateKeys(out key1, out key2) && !userData.Exists(x => x.PublicKey.IsCaseInsensitiveEqual(key1))) { var apiUser = new WebApiUserCacheData() { CustomerId = customerId, PublicKey = key1, SecretKey = key2, Enabled = true }; RemoveKeys(customerId); var attribute = new GenericAttribute() { EntityId = customerId, KeyGroup = "Customer", Key = WebApiUserCacheData.Key, Value = apiUser.ToString() }; _genericAttributeService.InsertAttribute(attribute); WebApiCaching.Remove(WebApiUserCacheData.Key); return true; } } } return false; }