【发布时间】:2008-12-09 18:09:27
【问题描述】:
我需要能够从 cron 任务或 ssh 会话中更改用户密码。有没有一种简单的方法可以使用 bash 脚本来做到这一点?如果没有,在 Cocoa 中最简单的方法是什么?
【问题讨论】:
我需要能够从 cron 任务或 ssh 会话中更改用户密码。有没有一种简单的方法可以使用 bash 脚本来做到这一点?如果没有,在 Cocoa 中最简单的方法是什么?
【问题讨论】:
Apple 在 Mac OS 10.5 中引入了CSIdentitySetPassword API,允许更改密码如下:
#import <Collaboration/Collaboration.h>
AuthorizationRef authRef = NULL; // You have to initialize authRef
CBIdentityAuthority *authority = [CBIdentityAuthority defaultIdentityAuthority];
CSIdentityRef identity = [CBIdentity identityWithName:user authority:authority].CSIdentity;
if (CSIdentityGetClass(identity) == kCSIdentityClassUser) {
CSIdentitySetPassword(identity, (__bridge CFStringRef)newPassword);
CSIdentityCommit(identity, authRef, NULL);
}
AuthenticationRef 可以像 int this response 一样初始化。
【讨论】:
使用passwd shell 命令。
【讨论】: