Last active
June 21, 2024 18:43
-
-
Save insin/dcf8a8c4acf27a8b1ffb478bcc7f4548 to your computer and use it in GitHub Desktop.
Mass update Firefox passwords (run in Tools → Web Developer → Browser Console) - https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox#Enabling_the_Browser_Toolbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updatePasswords() { | |
let oldPassword = prompt('Old password:') | |
if (!oldPassword) return | |
let loginManager = Components.classes['@mozilla.org/login-manager;1'] | |
.getService(Components.interfaces.nsILoginManager) | |
let matchingLogins = loginManager.getAllLogins().filter(l => l.password === oldPassword) | |
let matchCount = matchingLogins.length | |
if (matchCount === 0) return alert('No matching logins found') | |
let newPassword = prompt('New password:') | |
if (!newPassword) return | |
let confirmNewPassword = prompt('Confirm new password:') | |
if (!confirmNewPassword) return | |
if (newPassword !== confirmNewPassword) return alert('New passwords do not match') | |
if (!confirm(`Are you sure you want to update ${matchCount} password${matchCount === 1 ? '' : 's'}?`)) return | |
// Borrowed from mass_password_reset-1.05-tb+fx/content/oldpassword.xul | |
let nsLoginInfo = new Components.Constructor('@mozilla.org/login-manager/loginInfo;1', | |
Components.interfaces.nsILoginInfo, | |
'init') | |
for (login of matchingLogins) { | |
let updatedLogin = new nsLoginInfo( | |
login.hostname, | |
login.formSubmitURL, | |
login.httpRealm, | |
login.username, | |
newPassword, | |
login.usernameField, | |
login.passwordField | |
) | |
loginManager.modifyLogin(login, updatedLogin) | |
} | |
alert(`${matchCount} password${matchCount === 1 ? ' has' : 's have'} been updated`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment