我需要能够从cron任务或ssh会话更改用户的密码。有一个简单的方法来使用bash脚本吗?如果没有,在Cocoa中最简单的方法是什么?
答案 0 :(得分:1)
使用passwd
shell命令。
答案 1 :(得分:1)
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一样初始化。