Forgot Password
landynu
PROOP

20 days ago

Hey there,

When I set up my instance, I used my password generator to create the password and unfortunately I lost it. Is there any way to recover my account?

Forgot password email doesn't work because I never set up SMTP.

Solved$10 Bounty

Pinned Solution

hyper674
PROTop 10% Contributor

20 days ago

There’s no supported way to generate a compatible hash without using Better Auth itself.
If the secret is lost, then spinning up a new instance is unfortunately the only option.

7 Replies

hyper674
PROTop 10% Contributor

20 days ago

Hey, if you have direct access to your server/container where the instance is running, you can reset the password directly through the database or command line.


dev
MODERATOR

20 days ago

Template maintainer here, I'd try what the above post recommended, I'm don't know any other way personally


Status changed to Awaiting User Response Railway 20 days ago


landynu
PROOP

20 days ago

Thanks for the replies! Given that the passwords are hashed and encryption is done with BETTER_AUTH_SECRET variable, do either of you know how I would do this?

I already connected to my database and was able to view the hash, but I have no idea how to generate a password that would be recognized by the auth.

I could always just spin up a new template, but I figured I'd try this first to retain the data. I still can't believe that I failed to save the password haha.


Status changed to Awaiting Template Creator Response Railway 20 days ago


landynu

Thanks for the replies! Given that the passwords are hashed and encryption is done with BETTER_AUTH_SECRET variable, do either of you know how I would do this?I already connected to my database and was able to view the hash, but I have no idea how to generate a password that would be recognized by the auth.I could always just spin up a new template, but I figured I'd try this first to retain the data. I still can't believe that I failed to save the password haha.

hyper674
PROTop 10% Contributor

20 days ago

You won’t be able to “recover” the original password since it’s a one-way hash, but you can reset it as long as you still have the same BETTER_AUTH_SECRET.

Because Better Auth derives the password hash using that secret, the only way to generate a valid replacement is to rehash a new password using Better Auth’s own hashing function, not by manually editing the hash.


hyper674
PROTop 10% Contributor

20 days ago

There’s no supported way to generate a compatible hash without using Better Auth itself.
If the secret is lost, then spinning up a new instance is unfortunately the only option.


landynu
PROOP

20 days ago

Thanks all, I was able to get it to work! I was mistaken that I needed the BETTER_AUTH_SECRET

I downloaded a copy of the repository and ran the following in my IDE and then pasted in the password field right in Railway. I am sure there is a better way, but if anyone else loses their password, this worked!

cd "{{project_directory}}" && node -e "

import('better-auth/crypto').then(async (crypto) => {

const hash = await crypto.hashPassword('{{new_password}}');

console.log(hash);

});

"


hyper674
PROTop 10% Contributor

20 days ago

Glad I helped you


Status changed to Open Railway 20 days ago


Status changed to Solved dev 19 days ago


Loading...