Back

Password update of logged user

  • 0
  • Android
  • Accounts
  • Users
Harsh Panchal
18 Jun, 2023, 17:10

Hello, I want to update password for the logged in user in my android app(Kotlin). I'm using 2.0.x version of appwrite sdk and maybe I can't find the proper documentation for this version. When I downgrade the dependency version to 1.2.x or 1.3.x, I got an exception of "Invalid credentials. Please check email and password".

TL;DR
The user is trying to update the password for a logged-in user in their Android app using the Appwrite SDK. They are encountering an exception stating "Invalid credentials. Please check email and password" when downgrading the SDK version. They are seeking guidance on the correct code to update the password and how to fetch the old password of the user. One response recommends catching the error and showing a Toast to the user if the old password is incorrect. Another response suggests using the `account.get().password` code to fetch the old password. The recommended solution is to refer to the documentation and use version 1.3.x of the SDK for
D5
18 Jun, 2023, 17:46

Could you send the code you're using to update the password?

Drake
18 Jun, 2023, 21:22

Version 2.0.0 of the Android SDK is for Appwrite version 1.3.x (notice the 1st line of the SDK Readme).

Docs are here: https://appwrite.io/docs/client/account?sdk=android-kotlin&v=1.3.x#accountUpdatePassword

Drake
18 Jun, 2023, 21:24

You said

the update doesn't seem to be happening

Can you provide more detail? Perhaps you can print either the response or e to verify which part is being executed.

I would actually assume you're getting an error because you're not passing the old password.

Harsh Panchal
19 Jun, 2023, 10:03

I have the updated code like the following:

TypeScript
class UpdatePasswordActivity : AppCompatActivity() {
    private lateinit var binding: ActivityUpdatePasswordBinding

    @OptIn(DelicateCoroutinesApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityUpdatePasswordBinding.inflate(layoutInflater)
        setContentView(binding.root)

        AppwriteManager.initialize(this)

        binding.updatePasswordBtn.setOnClickListener {
            GlobalScope.launch {
                try {
                    val response = account.updatePassword(binding.password.text.toString(),null)
                    Toast.makeText(
                        this@UpdatePasswordActivity,
                        "Password updated successfully",
                        Toast.LENGTH_SHORT
                    ).show()
                    Log.d("UpdatePassword",response.toString())
                    //startActivity(Intent(this@UpdatePasswordActivity, LoginActivity::class.java))
                    //finish()
                } catch (e: AppwriteException) {
                    Log.d("UpdatePasswordException",e.message.toString())
                }
            }
        }
    }
}
Harsh Panchal
19 Jun, 2023, 10:03

Then got the exception like this

Drake
19 Jun, 2023, 14:45

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Drake
19 Jun, 2023, 14:45

Right... You didn't pass the correct old password...

retr122
20 Jun, 2023, 11:37

I'm recommend you to catch this error and make Toast to your users if new/old password is not correct.

Harsh Panchal
21 Jun, 2023, 06:37

Thanks. Will do it from now onwards 👍

Harsh Panchal
21 Jun, 2023, 06:40

How can I fetch the old password of the user? Like the following?:

TypeScript
account.get().password
Drake
21 Jun, 2023, 16:03

no...the user needs to input their old password...

D5
21 Jun, 2023, 17:01

Also it should not be possible nor recommended, since that means not using the default hashed system (it's insecure being able to get the password)

Harsh Panchal
22 Jun, 2023, 06:24

Understood. But if a user forgets his old password, what should he do?

Harsh Panchal
22 Jun, 2023, 06:38

I have also passed old password in parameter as below but still getting the same exception as UpdatePasswordException com.example.appwrite_userauth D Invalid credentials. Please check the email and password. :

TypeScript
        binding.updatePasswordBtn.setOnClickListener {
            GlobalScope.launch {
                try {
                    val response = account.updatePassword(binding.password.text.toString(),"12345678")
                    Toast.makeText(
                        this@UpdatePasswordActivity,
                        "Password updated successfully",
                        Toast.LENGTH_SHORT
                    ).show()
                    Log.d("UpdatePassword",response.toString())
                    //startActivity(Intent(this@UpdatePasswordActivity, LoginActivity::class.java))
                    //finish()
                } catch (e: AppwriteException) {
                    Log.d("UpdatePasswordException",e.message.toString())
                }
            }
        }
Drake
22 Jun, 2023, 16:52

This API is not for forgetting password...for that we have this: https://appwrite.io/docs/client/account?sdk=android-kotlin#accountCreateRecovery

Drake
22 Jun, 2023, 16:52

is that the correct old password?

Harsh Panchal
23 Jun, 2023, 10:53

Yes it was correct.

Harsh Panchal
23 Jun, 2023, 10:53

Okay, trying this way.

Harsh Panchal
23 Jun, 2023, 11:12

Can you tell me what will be the value for url ? I mean how can I redirect user to my app through url?

Drake
23 Jun, 2023, 14:29

according to the error, the old password was incorrect 🤷🏼‍♂️

Drake
23 Jun, 2023, 14:29
Harsh Panchal
25 Jun, 2023, 06:13

I am sorry for the inconvenience. I updated the password as the right password had been passed.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more