I’m trying to help users change their password after they have forgotten it and received a provisional password like wMjKyu67A
After they log in with the provisional password, I want them to be able to register a new one through a TextField and log them in right away or maybe take them to the Login Page. IDK yet. The point is, for this I have to update the password property in the ‘Users’ table through the API with the value typed.
I have tried with several Recipes, documentation from other SDKs, the Flutter SDKs git and Topics from this forum but havent been able.
This dude Cannot update user password is talking about a setPassword() method which isnt found in the Flutter SDK:
My Attempts:
Attempt 1:
//Sets new password and logs him in (takes him to the Home() page)
print("Updating user object without login.");
String id= user.getObjectId();
String pass=user.password;
print("My id is $id");
print("My Password is $pass");
user.setProperty("objectId", "$id");
user.setProperty("password", "jaja");
Backendless.userService.update(user).then((user) {
print("User has been updated");
print("Password - ${user.getProperty("password")}");
});
The best way to update password for user i to use Backendless.userService.update func.
After getting BackendlessUser object you can set new password in two ways:
The second approach in fact is calling setter for password property. You shouldn’t confuse it with calling setPassword() method. In this case it looks like just setting the property directly.
You can read more in language tour: https://dart.dev/guides/language/language-tour#getters-and-setters
But I’ve found the bug with Backendless.userService.update on iOS. It will be fixed in the next release of BackendlessSwift, which is the dependency of Flutter-SDK.
As a workaround you’re able to use this code:
final user = await Backendless.userService.login("email@email.com", "temp_password");
Map<dynamic, dynamic> entity = {"objectId": user.getObjectId(), "password": "new_password"};
final savedEntity = await Backendless.data.of("Users").save(entity);
print("Check saved entity: $saved");
// Do this to check, that password was saved correctly
await Backendless.userService.logout();
final userWithUpdatedPass = await Backendless.userService.login("email@email.com", "new_password");
print("Did login with new password");