LoginViewController.h
//
// LoginViewController.h
// ProtectedData
//
// Created by on 7/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "LockView.h"
@interface LoginViewController : UIViewController <LockViewDelegate>
// 在屏幕上方显示字符串
@property (nonatomic, strong) UILabel *loginAppLabel;
@property (nonatomic, strong) LockView *lockView;
@end
LoginViewController.m
//
// LoginViewController.m
// ProtectedData
//
// Created by on 7/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "LoginViewController.h"
#import "AppDefine.h"
#import "NSString+MD5HexDigest.h"
#import "PasswordListViewController.h"
@implementation LoginViewController
@synthesize loginAppLabel;
@synthesize lockView;
- (id)init
{
self = [super initWithNibName:nil bundle:nil];
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
return [self init];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[self.navigationController setNavigationBarHidden:YES];
[super viewDidLoad];
[self.view setUserInteractionEnabled:YES];
self.view.backgroundColor = [UIColor clearColor];
self.lockView = [LockView instanceWithFrame:self.view.bounds WithDelegate:self];
[self.view addSubview:self.lockView];
self.loginAppLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 20.0f, self.view.bounds.size.width - 40.0f, 46.0f)];
self.loginAppLabel.backgroundColor = [UIColor clearColor];
self.loginAppLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.loginAppLabel setTextAlignment:UITextAlignmentCenter];
[self.loginAppLabel setTextColor:[UIColor whiteColor]];
[self.loginAppLabel setFont:[UIFont boldSystemFontOfSize:30.0f]];
self.loginAppLabel.text = NSLocalizedString(@"LoginAppLabelText", nil);
[self.view addSubview:self.loginAppLabel];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - LockViewDelegate
- (void)beforeUnlocking
{
}
- (void)beganUnlock
{
}
- (void)unlocking
{
}
- (void)afterUnlock
{
NSMutableString *unlockKey = [NSMutableString string];
for (NSNumber *index in self.lockView.lastSelectedButtonsIndexArray) {
[unlockKey appendFormat:@"%i", index.integerValue];
}
NSString *unlockKeyWithMd5 = [NSString stringWithString:[unlockKey md5HexDigest]];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *userDefaultsUnlockKeyWithMd5 = [userDefaults stringForKey:USERDEFAULTAPPLOCKKEY];
if ([unlockKeyWithMd5 isEqualToString:userDefaultsUnlockKeyWithMd5]) {
PasswordListViewController *passwordListViewController = [[PasswordListViewController alloc] init];
[self.navigationController pushViewController:passwordListViewController animated:YES];
} else {
[self.lockView resetButtons];
}
}
@end