'bcrypt password is changing after a time

I have created a app similar to blog app. Users can registered and login logout. When User creates it's account than logout than s/he can login again with the same password. However, after a spesific time(I couldn't specify the time exactly but more than 1 day) when user try to login with the same password and username. Bcrypt returns false.

This is function when user try to login.

userSchema.statics.login = async function(username,password){


const user = await this.findOne({username})
if (user){
    const auth = await bcrypt.compare(password,user.password)
    console.log(auth)
    if (auth){
        return user
    }else{
        throw Error('Password is wrong.')
    }
}else{
    throw Error('Username doesn\'t exist.')
}}

This is the function when user registers.

userSchema.pre('save', async function(next){
const salt = await bcrypt.genSalt()
this.password = await bcrypt.hash(this.password,salt)
next()
})


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source