-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangeAccountPassword.sh
More file actions
40 lines (35 loc) · 1.29 KB
/
Copy pathchangeAccountPassword.sh
File metadata and controls
40 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
# Provide a ";" seperated list of potential old passwords
oldPasswords="oldPassword1;oldPassword2;oldPassword3"
# New password to use
newPassword="newPassword"
# Useraccount for which the password is to be changed
userAccount="adminAccount"
IFS=';'
changePassword() {
# Change account password
/usr/bin/dscl . passwd /Users/${userAccount} "${1}" "${newPassword}"
# Change keychain password
sudo security set-keychain-password -o "${1}" -p "${newPassword}" /Users/${userAccount}/Library/Keychains/login.keychain
# Find users generatedUUID
uuid=$(dscl . -read /Users/${userAccount} GeneratedUID | cut -c 15-)
# Change filevault password using the UUID gathered above
diskutil apfs changePassphrase / -user "${uuid}" -oldPassphrase "${1}" -newPassphrase "${newPassword}"
exit 0
}
echo "Changing password for account: $userAccount"
# Loop over the potential old passwords
for password in $oldPasswords
do
# Trying a password, triggering the changePassword function
# if case the provided password is correct.
echo "Trying password: $password"
sudo su - ${userAccount} -c "echo \"${password}\" | sudo -Sv"
if [ $? -eq 0 ]; then
echo "Correct password, continuing"
changePassword "${password}"
else
echo "Wrong password, attempting next..."
fi
done
exit 1