Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här återställer du WordPress Admin Password på Localhost

Att bli utelåst från din lokala WordPress-webbplats kan stoppa ditt arbete. Vi har varit med om detta när vi testat teman eller satt upp kundprojekt i den lokala miljön.

Det frustrerande är att e-postmeddelanden om återställning av lösenord inte fungerar på lokala host-inställningar. Så även om du klickar på “Har du tappat bort ditt lösenord?” kommer det inte upp något i din inkorg.

Tack och lov finns det enkla sätt att återställa ditt WordPress-adminlösenord utan att behöva e-poståtkomst. Vi har använt dessa metoder otaliga gånger för att komma tillbaka till våra lokala webbplatser.

I den här guiden visar vi dig hur du återställer ditt WordPress-adminlösenord på localhost med phpMyAdmin eller WP-CLI – beroende på vad som känns bekvämast för dig.

Resetting the admin password in WordPress on localhost

Varför återställning av lösenordet inte fungerar på Localhost

När vi säger “localhost” talar vi om en lokal server – vanligtvis din dator. Det är ett privat utrymme där du kan bygga och testa en WordPress-webbplats innan du går live.

Vi använder ofta localhost för att experimentera med nya plugins, designändringar eller bara lära oss hur WordPress fungerar. Det är ett säkert sätt att bryta saker utan att oroa sig.

Om du inte har provat det ännu kan de här guiderna hjälpa dig att komma igång:

Nu kommer den del som kan vara förvirrande för nybörjare. Om du glömmer ditt administratörslösenord på en lokal webbplats hjälper inte den vanliga länken “Har du glömt ditt lösenord?”.

Det beror på att WordPress normalt skickar ett e-postmeddelande om återställning av lösenord, men inställningar för lokala värdar kan inte skicka e-postmeddelanden om du inte har ställt in det manuellt. Och som standard har de flesta människor inte gjort det.

Lyckligtvis behöver du inte ett e-postmeddelande för att komma in igen. Vi ska visa dig två enkla sätt att återställa ditt lösenord på localhost, även om du är helt utelåst.

Metod 1: Återställ WordPress Admin-lösenord på Localhost med hjälp av phpMyAdmin

Om du använder verktyg som XAMPP, WAMP eller MAMP bör phpMyAdmin redan vara installerat. Vi har använt det många gånger för att justera saker direkt i databasen – inklusive återställning av lösenord.

phpMyAdmin ger dig ett visuellt gränssnitt för att hantera din WordPress-databas. Det låter komplicerat, men när du väl har lärt dig hur det fungerar är det ganska enkelt.

Obs: Om du använder LocalWP kommer du att se ett verktyg som heter Adminer istället. Det fungerar precis som phpMyAdmin, så du kan fortfarande följa dessa steg enkelt.

Adminer the phyMyAdmin alternative in LocalWP

Börja med att öppna din webbläsare och gå till den här adressen:

http://localhost/phpmyadmin/

Du kan bli ombedd att logga in. I de flesta installationer är användarnamnet root och lösenordsfältet lämnas tomt.

När du är inne i phpMyAdmin letar du efter namnet på din WordPress-databas i sidofältet och klickar på det.

Open your database in phpMyAdmin

Du kommer att se en lista över tabeller i den databasen. Leta reda på den som slutar på _users och klicka på länken Bläddra bredvid den.

Obs: De flesta WordPress-webbplatser använder wp_ som prefix, men det kan vara annorlunda om du ändrade det under installationen.

Open users table in WordPress database

Du kommer nu att se en lista över användare på din webbplats. Leta reda på raden med användarnamnet admin och klicka på länken Redigera bredvid den.

Edit user in WordPress database

Detta öppnar ett formulär som visar alla användardata som finns lagrade i databasen. Bläddra ner tills du hittar fältet user_pass.

Skriv in ditt nya lösenord i kolumnen Value. I kolumnen Funktion väljer du sedan MD5 i rullgardinsmenyn.

Add new user password

Detta steg är viktigt – WordPress lagrar lösenord med hjälp av kryptering och MD5 hjälper till att känna igen formatet.

Klicka på knappen Go längst ned för att spara dina ändringar.

Save database changes

Nu är det klart! Du kan nu logga in på din lokala WordPress-webbplats med det nya lösenordet som du just angav.

Metod 2: Återställning av lösenordet via filen Functions.php

Om du inte har tillgång till phpMyAdmin eller föredrar ett annat tillvägagångssätt kan du återställa ditt WordPress-adminlösenord genom att redigera filen functions.php i ditt tema . Denna metod är okomplicerad och kan göras snabbt.

Steg 1: Öppna ditt temas Functions.php-fil

Först måste du leta reda på filen functions.php för ditt aktiva tema. För att göra detta navigerar du till rotkatalogen för din WordPress-installation på ditt lokala webbhotell.

Beroende på vilken programvara du använder kan platsen för rotkatalogen skilja sig åt. Om du t.ex. använder Local kommer din webbplats att ligga på:

C:\användare\ditt användarnamn\lokala webbplatser\ditt användarnamn\app\allmänhet\

Gå sedan till mappen /wp-content/themes/. Där hittar du en mapp som är uppkallad efter ditt aktiva tema.

Locating your theme folder

I din aktiva temamapp letar du efter en fil med namnet functions.php och öppnar den i en textredigerare som Notepad eller TextEdit.

Steg 2: Lägg till koden för att återställa lösenordet

Längst ner i filen functions.php måste du klistra in följande kod :

function reset_admin_password() {
    $user_id = 1; // ID of the admin user
    $new_password = 'newpassword123'; // Your new password
    wp_set_password($new_password, $user_id);
}
add_action('init', 'reset_admin_password');

Glöm inte att ersätta “newpassword123” med ett starkare lösenord som du vill använda.

Den här koden anger ett nytt lösenord för administratörsanvändaren med ID 1. Om du inte känner till användar-ID men känner till administratörens e-postadress kan du använda det här kodavsnittet istället:

function reset_admin_password_by_email() {
    $user_email = 'admin@example.com'; // Admin user's email address
    $user = get_user_by('email', $user_email);
    if ($user) {
        $new_password = 'newpassword123'; // Your new password
        wp_set_password($new_password, $user->ID);
    }
}
add_action('init', 'reset_admin_password_by_email');

Den här koden anger ett nytt lösenord(newpassword123) för administratörsanvändaren som är kopplad till den angivna e-postadressen.

När du har lagt till koden sparar du filen functions.php och uppdaterar WordPress-webbplatsen på ditt lokala webbhotell i webbläsaren. Du bör nu kunna logga in med det nya lösenordet.

Steg 4: Ta bort koden

När du väl har loggat in är det viktigt att ta bort kodsnutten från filen functions.php för att undvika potentiella säkerhetsrisker .

Öppna bara filen functions.php och ta bort den kod du lade till tidigare . Glöm inte att spara dina ändringar.

Bonusresurser:

Här följer ytterligare tips och handledningar för hantering av lösenord och adminkonton i WordPress:

Vi hoppas att den här artikeln hjälpte dig att återställa ditt administratörslösenord för WordPress på en lokal server. Du kanske också vill se vår handledning om hur du skapar en tillfällig inloggning för WordPress eller ta en titt på vår guide om hur du lägger till Google-inloggning med ett klick i WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

63 kommentarerLeave a Reply

  1. Hafiz Muhammad Ansar

    Very nice blog for WordPress help. I recommend for beginners to use this platform. Thankful!

    • WPBeginner Support

      Glad you found our article helpful!

      Admin

  2. Abdullah

    Amazing, it worked

    • WPBeginner Support

      Glad our guide was helpful!

      Admin

  3. Nidhi Gupta

    it’s really helpful, thankyou so much

    • WPBeginner Support

      Glad our guide was helpful!

      Admin

  4. Habu

    Omg you save my life !!! THANK YOU VERY MUCHH !!!

  5. Jahir

    I can not log in now same process…any updates?

    • WPBeginner Support

      The most common issue would be if you did not set the function to MD5 or click go to apply the changes, you would want to ensure you have done that correctly.

      Admin

  6. Kamondo

    Wonderful! problem solved. Very Simple steps but powerful.

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  7. Joe

    I’m encoutering this problem now after installing the 2nd WordPress on MAMP. This article is very to the point and I’ll try it tomorrow!

    • WPBeginner Support

      We hope the guide helps :)

      Admin

  8. Gerron

    Solid solid info right here, thanks a lot, really helped, so simple

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  9. Odineks

    Thank you so much. I always find solutions to every of my WP problems here.
    I kept having problems with the login page on the frontend not recognizing my new password, I didn’t realize there is a function to pass that message to myPHPadmin.

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  10. naved ahmed

    Thanks a lot. Finally problem solved within a minute.

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  11. Mohsin

    I just love this
    Love the way you write every thing

    • WPBeginner Support

      Thank you, glad you like our content :)

      Admin

  12. Jen

    I tried this and while I was in there also attempted to change my username, which I realize was probably my mistake… but now I can’t log in at all. Is there a way to undo what I’ve done?

    • WPBeginner Support

      You would need to follow the steps in the article and that would bring you back to where you could edit, you should also be able to use your email as an alternative

      Admin

  13. Justina

    Your Blog is always so full of rich articles. Thanks so much. was stuck for a while because I skip the MD5 option. You are a lifesaver.

    • WPBeginner Support

      Glad our guide could be helpful :)

      Admin

  14. Sarah

    Thank you SO MUCH for this! You saved me so many more hours of tinkering with trying to figure out how to log in!!

    • WPBeginner Support

      Glad we were able to help :)

      Admin

  15. David

    Thank you ever so much! Normally, I keep this stuff handy; but in this case, I did could not find where I wrote the information down.

    You saved a total re-work of a site I was planning.

    • WPBeginner Support

      Glad our guide could be helpful :)

      Admin

  16. adeel kamran

    You saved me, I had a lot of work there.

    • WPBeginner Support

      Glad our guide could help :)

      Admin

  17. lokesh n

    thank you it’s really working thank you

    • WPBeginner Support

      You’re welcome glad our article was helpful :)

      Admin

  18. Vivek

    Hi,
    When I reset My password through link then what fileds affected in Database and in which table.

    Kindly share this information i am waiting for your response.

  19. Adnan Khan

    After half an hour of search i just found my help from this site, which solves my problem in no time,
    thanks a lot
    keep it up guys

    • WPBeginner Support

      You’re welcome, glad our guides can be helpful :)

      Admin

  20. Tenasu Mensah

    thanks a lot, kudos to you guys keep the good work doing,you guys are doing great job

    • WPBeginner Support

      Glad our guide could help :)

      Admin

  21. Anuj

    It work fine, Thanku so much,

  22. Pádraig

    Really simple and great explanation.

    Many thanks for sharing.

  23. Saranya

    Works Good! Thanks a lot.

  24. Patr

    Hello,
    I type a new password , click continue and it does not keep the password, it shows a long string of numbers and letters. If I use this , still cannot log in. It looks simple on the video but does not work for me. Thank you.
    I looked everywhere on the internet, no solution worling.

    • Jason

      Same problem here. Did you find a solution? Is there any chance of being hacked?

  25. Christian Gochez

    when I click on the Go button this error appears:

    #1881 – Operation not allowed when innodb_forced_recovery > 0

  26. Edward

    Simple and neat! worked thanks

  27. Handel

    I started to just reinstall wordpress, but then decided to do a google search, and there was GOOD OLD RELIABLE WpBeginner.com

    Thanks a million!!

  28. Sheriff

    very effective… kudos

  29. Icholia

    Hello

    THANKS, Wow there is no other place that you can get well explained information like this , i have been suffering but now i just followed your tutorial and it is a game changer i love you guys and i will always learn from you guys once again thanks

  30. CJ

    Thank you! For those who can’t make it work, remember to use the “MD5” function when changing the password. I almost skipped that part and was stuck for a few minutes.

  31. mohamad hossein

    so use full thank you so much

  32. Janet

    I got completely lost on the video so I tried plugging in the URL. Doesn’t work. Still lost.

  33. Ma

    Thanks so much, you saved me from what could have been a very embarrassing situation!

  34. James

    I change the password, username, userlogin and nickname not I cant login. Any advice?

    • suganya

      i can’t able to login .because it’s shows me like email is not registered .so what can i do???

  35. Jac

    Thanks so much for providing this info – I was really stuck!

  36. Gerhard SCHNEIBEL

    Thanks a lot for your help. I am very happy with “wpbeginners”.

  37. Renu

    it worked.. thanks a ton..

  38. Anthony

    Hi…
    I am so thankful for such great information you provide. I have bookmarked your site a while back.
    I have been working on a site in wordpress using xampp on the Apache local server. Just recently, I am not able to login on the admin page. I have managed to create a user name and password that works on about 95% of all sites requiring me to register. I also created a file that lists all my login info for everywhere I need to login, including the WP admin login page, IF I ever forget that info.
    I have read this page (https://www.wpbeginner.com/wp-tutorials/how-to-reset-wordpress-admin-password-on-localhost/) and watched the video, also. The only problem is that when I click on the wp_users in phpMyadmin, I get this error- ‘#1932 – Table ‘bitnami_wordpress.wp_users’ doesn’t exist in engine.’
    Am I reduced to re-installing WordPress, or is there another way around it?
    I have tried restoring my computer (using system restore) to various past restore points, but with no luck. Can you help me with this?
    I would be so thankful!!! I have put months of work into designing a site to launch, and I HAVE exported everything to a file quite a few times using WordPress import plugin (something like that).

    Could you provide a solution?

    Thank you so much…

    Anthony

  39. Kakaire Charles

    Extremely wonderful. Thank you for sharing.

  40. Gaurav

    i tried this but not working

  41. shaikh muneer

    super way to reset admin password thank you for share this

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.