Login as user (auto login)

I would like to create an admin function in our app that will allow me to login as a user on the system. Like many admin systems I would like to be able to view a users dashboard as them and as a function that will allow me to “view as user” or “login as user” link from our apps admin dashboard.

Does anyone have any idea how this could be accomplished? My idea is to briefly change the password for the user then somehow login as the user using the updated password credential then immediately after logging in switch the password back to the old one if this is even possible since its hashed. Hopefully I can just copy the hashed password then change it back.

Any ideas how this login as user function could be created?