Simple |
Updates the password.
Namespace: Gamanet.C4.SDK
Assembly: Gamanet.C4.SimpleClient (in Gamanet.C4.SimpleClient.dll) Version: 2026.0.0.733
Syntax
C#
public void UpdatePassword( string userName, SecureString oldPassword, SecureString newPassword )
Parameters
- userName String
- Name of the user.
- oldPassword SecureString
- The old password.
- newPassword SecureString
- The new password.
Implements
ISimpleClientV1.UpdatePassword(String, SecureString, SecureString)Example
The following example illustrates how SimpleClient updates password.
C#
using Gamanet.C4.SDK; using Gamanet.C4.SDK.Enums.Core; using Gamanet.C4.SDK.Enums.Persons; using Gamanet.C4.SimpleInterfaces; using SCExampleCore; using System; using System.Collections.Generic; using System.Security; public class UpdatePassword { static void Main() { // create instance of simple client var client = new SimpleClient(ConnectorConfiguration.HttpClient); ConnectionInfo token; // connect to local server var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support", out token); if (connectionResult != ConnectionResult.Successful) { Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult); Console.ReadLine(); return; } Console.WriteLine("Connection result: {0}", connectionResult); Console.WriteLine(); // create new instance of SimplePerson var person = new SimplePerson(Guid.NewGuid(), "Bob", EntityRoot.Person, PersonCategory.Person) { Data = new Dictionary<string, object> { ["Surname"] = "Bob", } }; // create forms authentication for person var password = "oldPass"; var salt = PasswordHashUtility.CreateRandomBytes(16); // create salt var hash = PasswordHashUtility.CalculateHash(password, salt); // create hash person.Data["auth_Type"] = AuthenticationType.FormsAuthentication; person.Data["auth_Account"] = "Bob"; person.Data["auth_HashedPassword"] = hash; person.Data["auth_Salt"] = salt; // create person in db client.Persons.Create(person); // disconnect from server client.Disconnect(); Console.WriteLine("Connect to server with person's credential"); // Connect to server with person's credential connectionResult = client.Connect(new Uri("https://localhost/"), "Bob", "oldPass", out token); if (connectionResult != ConnectionResult.Successful) { Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult); Console.ReadLine(); return; } Console.WriteLine("Connection result: {0}", connectionResult); // Instantiate the secure string. SecureString oldPass = new SecureString(); // Assign the string to the secure string. foreach (char ch in password) oldPass.AppendChar(ch); password = "newPass"; // Instantiate the secure string. SecureString newPass = new SecureString(); // Assign the string to the secure string. foreach (char ch in password) newPass.AppendChar(ch); client.UpdatePassword("Bob", oldPass, newPass); Console.WriteLine(); Console.WriteLine("Password updated."); // disconnect from server client.Disconnect(); // try to connect with old password connectionResult = client.Connect(new Uri("https://localhost/"), "Bob", "oldPass", out token); Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult); // try to connect with new password connectionResult = client.Connect(new Uri("https://localhost/"), "Bob", "newPass", out token); Console.WriteLine("Connection unsuccessful, result: {0}", connectionResult); // disconnect from server client.Disconnect(); // Connection result: Successful // Connect to server with person's credential // Connection result: Successful // Password updated. // Connection unsuccessful, result: InvalidCredentials // Connection unsuccessful, result: Successful } }
See Also