IOS Как использовать системный пароль для запуска скрипта? ⇐ IOS
-
Anonymous
IOS Как использовать системный пароль для запуска скрипта?
I am creating a macOS app (using SwiftUI), it will run a script. To run a script I need the system (or admin) password. because when I run that script in Terminal it asked the user password and than run the script. I am able to run the script on button click with a securefeild, but It's not the appropriate to show user a securefeild and ask his system password in the app, while its against the apple guide line. So I removed that feild. Now I dont have any idea how to run script after System password authentication. To show user authentication I am using this.
let context = LAContext() func authorize() { var error: NSError? = nil // Create optional error variable let reason = "This action requires your authentication for security purposes." let policy: LAPolicy = .deviceOwnerAuthentication // Adjust policy based on device capabilities (e.g., biometrics, passcode) context.evaluatePolicy(policy, localizedReason: reason, reply: { (success, error) in if success { // User was successfully authenticated **// Proceed with your script execution here, but the problem is I dont have user password here, and not found even from the Keychain, because before fetch password from keychain it should be store there** print("Success") } else { // Authentication failed or was canceled if let error = error { // Handle the error appropriately print(error.localizedDescription) } } }) } I think, I should save the password in keychain for security and than access but, first I need to get the password without breaking the apple guide lines.
Thats the whole problem, I did not found related this thing.
Edited:
When I run my script in the success case, it shows the message in the Xcode below terminal.
sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
Источник: https://stackoverflow.com/questions/780 ... n-a-script
I am creating a macOS app (using SwiftUI), it will run a script. To run a script I need the system (or admin) password. because when I run that script in Terminal it asked the user password and than run the script. I am able to run the script on button click with a securefeild, but It's not the appropriate to show user a securefeild and ask his system password in the app, while its against the apple guide line. So I removed that feild. Now I dont have any idea how to run script after System password authentication. To show user authentication I am using this.
let context = LAContext() func authorize() { var error: NSError? = nil // Create optional error variable let reason = "This action requires your authentication for security purposes." let policy: LAPolicy = .deviceOwnerAuthentication // Adjust policy based on device capabilities (e.g., biometrics, passcode) context.evaluatePolicy(policy, localizedReason: reason, reply: { (success, error) in if success { // User was successfully authenticated **// Proceed with your script execution here, but the problem is I dont have user password here, and not found even from the Keychain, because before fetch password from keychain it should be store there** print("Success") } else { // Authentication failed or was canceled if let error = error { // Handle the error appropriately print(error.localizedDescription) } } }) } I think, I should save the password in keychain for security and than access but, first I need to get the password without breaking the apple guide lines.
Thats the whole problem, I did not found related this thing.
Edited:
When I run my script in the success case, it shows the message in the Xcode below terminal.
sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
Источник: https://stackoverflow.com/questions/780 ... n-a-script
Мобильная версия