Created
October 14, 2023 16:29
-
-
Save kepocnhh/242b43a21ab4d48edc1530d3b99564e8 to your computer and use it in GitHub Desktop.
OS X security sample with warning.
This file contains 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
SERVICE_NAME='service_foo' | |
ACCOUNT_NAME='account_bar' | |
PASSWORD_VALUE='password_bar' | |
security delete-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" &> /dev/null | |
# Add a generic password item to the default keychain. | |
security add-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" -w "$PASSWORD_VALUE" -T '' | |
if test $? -ne 0; then | |
echo 'Add password error!'; exit 1; fi | |
# Find a generic password item and display the password(only) for the item found. | |
PASSWORD_ACTUAL=$(security find-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" -w) | |
if test $? -ne 0; then | |
echo 'Find password error!'; exit 1; fi | |
if test "$PASSWORD_ACTUAL" != "$PASSWORD_VALUE"; then | |
echo 'Password error!'; exit 1; fi | |
echo 'Password as expected.' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment