Misc/Resetting Unifi Controller Password with MongoDB CLI
Directions for resetting the admin users password on a Unifi Controller. I did this for a Unifi Network Controller running off of a Windows machine.
Resetting the password
First download the MongoDB CLI tool using either of these two links. I have tested this on older Unifi Controller versions all the way up to version 9.5
https://archive.org/download/mongodb-win32-x86_64-3.2.0/mongodb-win32-x86_64-3.2.0.zip
https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-3.2.0.zip
Extract the zip file and open it with CMD.exe (not powershell)
Run the following command to print out the admin users username and encrypted password
mongo.exe --port 27117 ace --eval "db.admin.find().forEach(printjson);"
The output should resemble this:
CMD> mongo.exe --port 27117 ace --eval "db.admin.find().forEach(printjson);"
[...]
},
"x_shadow" : "$6$9Ter1EZ9$lSt6/tkoPguHqsDK0mXmUsZ1WE2qCM4m9AQ.x9/eVNJxws.hAxt2Pe8oA9TFB7LPBgzaHBcAfKFoLpRQlpBiX1",
"name" : "admin",
"time_created" : NumberLong(1764786455),
"email" : "[email protected]",
"last_login_timestamp" : NumberLong(1764789489),
"last_login_ip" : "127.0.0.1"
}
[...]
The Unifi controller password is stored encrypted using the SHA512 Crypt(3) $6$
algorithm. Use the command below to change the password for "admin" to be
"password". To set a custom password, use a hash calculator to create a new
password using SHA512 Crypt(3) $6$. Modify the command below and replace the
existing hash ($6$[...]iX1) with the newly generated hash
Hash Calculator: https://tomi.cc/hash/
mongo.exe --port 27117 ace --eval ^"db.admin.update^( { \^"name\^" : \^"admin\^" }, { $set : { \^"x_shadow\^" : \^"$6$9Ter1EZ9$lSt6/tkoPguHqsDK0mXmUsZ1WE2qCM4m9AQ.x9/eVNJxws.hAxt2Pe8oA9TFB7LPBgzaHBcAfKFoLpRQlpBiX1\^" } } ^)^"