2010-06-30 12:09:58 +00:00
|
|
|
@import "sha1.js"
|
|
|
|
|
|
|
|
@implementation YModel : CPObject
|
|
|
|
{
|
|
|
|
CPString _url;
|
|
|
|
CPString _masterPassword;
|
|
|
|
int _length;
|
|
|
|
int _uid;
|
|
|
|
CPString _hashType;
|
|
|
|
RegExp domainRegexp;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
[self setUrl:@""];
|
|
|
|
[self setLength:27];
|
|
|
|
[self setUid:0];
|
|
|
|
[self setType:@"base64"];
|
|
|
|
[self setMasterPassword:@"|\\/|4573R"];
|
|
|
|
domainRegexp = new RegExp("^(.*://)?([^/]*?\\.)?([^/.]*\\.[^/.]*)(/.*?)?$");
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMasterPassword:(CPString)aMasterPassword
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: setMasterPassword:%s", aMasterPassword);
|
2010-06-30 12:09:58 +00:00
|
|
|
_masterPassword=aMasterPassword;
|
|
|
|
}
|
|
|
|
- (CPString) masterPassword
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: masterPassword: %d",_masterPassword);
|
2010-06-30 12:09:58 +00:00
|
|
|
return _masterPassword;
|
|
|
|
}
|
|
|
|
- (void) setType:(CPString)anHashType
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: setType:%s", anHashType);
|
2010-06-30 12:09:58 +00:00
|
|
|
_hashType=anHashType;
|
|
|
|
}
|
|
|
|
- (CPString) type
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: hashType: %d",_hashType);
|
2010-06-30 12:09:58 +00:00
|
|
|
return _hashType;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setUrl:(CPString)aURL
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: setUrl:%s", aURL);
|
2010-06-30 12:09:58 +00:00
|
|
|
_url=aURL;
|
|
|
|
}
|
|
|
|
- (CPString) url
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: url: %d",_url);
|
2010-06-30 12:09:58 +00:00
|
|
|
return _url;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setLength:(int)aLength
|
|
|
|
{
|
|
|
|
aLength=parseInt(aLength);
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: setLength:%d", aLength);
|
2010-06-30 12:09:58 +00:00
|
|
|
_length=aLength;
|
|
|
|
}
|
|
|
|
- (int) length
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: length: %d",_length);
|
2010-06-30 12:09:58 +00:00
|
|
|
return _length;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setUid:(int)anUid
|
|
|
|
{
|
|
|
|
uid=parseInt(anUid);
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: setUid:%d", anUid);
|
2010-06-30 12:09:58 +00:00
|
|
|
_uid=anUid;
|
|
|
|
}
|
|
|
|
- (int) uid
|
|
|
|
{
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: uid: %d",_uid);
|
2010-06-30 12:09:58 +00:00
|
|
|
return _uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CPString) domain
|
|
|
|
{
|
|
|
|
return _url.replace(domainRegexp,"$3");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CPString) password
|
|
|
|
{
|
|
|
|
var toencrypt=[self masterPassword];
|
|
|
|
var hash;
|
|
|
|
if ( _uid > 0 ) {
|
|
|
|
toencrypt=toencrypt+[self uid];
|
|
|
|
}
|
|
|
|
toencrypt=toencrypt+[self domain];
|
|
|
|
if ( _hashType == "base64" ) {
|
|
|
|
hash = b64_sha1(toencrypt);
|
|
|
|
} else if ( _hashType == "hexa" ) {
|
|
|
|
hash = hex_sha1(toencrypt);
|
|
|
|
} else {
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"[YModel] password: unknown hashType: '%s'", hashType);
|
2010-06-30 12:09:58 +00:00
|
|
|
}
|
2010-06-30 12:54:11 +00:00
|
|
|
// console.log(@"YModel: password (toencrypt: %s)", toencrypt );
|
2010-06-30 12:09:58 +00:00
|
|
|
return hash.substr(0,[self length]);
|
|
|
|
}
|
|
|
|
@end
|