/// <summary> /// Registers a new user using the given password key to decrypt their password /// </summary> /// <param name="newUser"></param> /// <param name="passwordKey"></param> public void Register(User newUser, string passwordKey, string facebookAuthCode) { // check if user already exists List <User> allUsers = DataManager.GetDataContext <User>().GetAll <User>(); if (allUsers.Any(u => u.UserName == newUser.UserName)) { throw new Exception(USER_EXISTS); } if (newUser.SyncWithFacebook) { newUser.FacebookAccessToken = FacebookManager.GetFacebookAccessToken(facebookAuthCode); } // decrypt password string decrypted = EncryptionUtility.Decrypt(passwordKey, newUser.Password); // re-encrypt password with server key string serverEncrypt = EncryptionUtility.Encrypt(ServerPasswordKey, decrypted); // set the user's password to the server-encrypted version newUser.Password = serverEncrypt; // add the users to the data context and save DataManager.GetDataContext <User>().AddObjects <User>(new User[] { newUser }.ToList()); DataManager.GetDataContext <User>().Save(); // add the user the logged on users if (!LoggedOnUsers.Any(u => u.Email == newUser.Email)) { LoggedOnUsers.Add(newUser); } }