-
Notifications
You must be signed in to change notification settings - Fork 3
/
PasswordWindowController.m
76 lines (71 loc) · 2.06 KB
/
PasswordWindowController.m
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// PasswordWindowController.m
// Jabber
//
// Created by David Chisnall on 22/09/2004.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//
#import "PasswordWindowController.h"
#import "JabberApp.h"
//Keychain OS X only at the moment
//TODO: Move this into the framework in a nice PasswordManager class
//TODO: Change this to a NOKEYCHAIN macro not GNUSTEP.
#ifdef GNUSTEP
void setPasswordForAccount(NSString * password, JID * account)
{
NSMutableDictionary * passwords = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"XMPPPasswords"]];
if(passwords == nil)
{
passwords = [NSMutableDictionary dictionary];
}
[passwords setObject:password forKey:[account jidString]];
[[NSUserDefaults standardUserDefaults] setObject:passwords
forKey:@"XMPPPasswords"];
}
#else
#include <Security/Security.h>
void setPasswordForAccount(NSString * password, JID * account)
{
SecKeychainAddInternetPassword(NULL,
[[account domain] length],
[[account domain] UTF8String],
0,
NULL,
[[account node] length],
[[account node] UTF8String],
0,
NULL,
5222,
kSecProtocolTypeTelnet, //This is wrong, but there seems to be no correct answer.
kSecAuthenticationTypeDefault,
[password length],
[password UTF8String],
NULL);
}
#endif
@implementation PasswordWindowController
- (id) initWithWindowNibName:(NSString*)windowNibName forJID:(JID*)_jid
{
myJID = _jid;
return [self initWithWindowNibName:windowNibName];
}
- (void)windowDidLoad
{
[question setStringValue:[NSString stringWithFormat:@"%@%@",
[question stringValue],
[myJID jidStringWithNoResource]]];
}
- (void) yes:(id)sender
{
NSString * password = [passwordBox stringValue];
setPasswordForAccount(password, myJID);
[[self window] close];
[NSApp stopModalWithCode:0];
}
- (void) no:(id)sender
{
[[self window] close];
[NSApp stopModalWithCode:-1];
[NSApp terminate:self];
}
@end