对密码加密

This commit is contained in:
2014-09-23 09:29:36 +08:00
parent 75269d1a20
commit bd7ae26fd4
10 changed files with 63 additions and 18 deletions
+2
View File
@@ -56,4 +56,6 @@
//时间戳转时间
+(NSString*)timeFromtimeSp:(NSString*)timeSp;
//md5加密
+(NSString*)md5:(NSString *)str;
@end
+15
View File
@@ -9,6 +9,7 @@
#import "ManagerUtil.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
#import <CommonCrypto/CommonDigest.h>
@implementation ManagerUtil
@@ -182,4 +183,18 @@
NSDate * date = [NSDate dateWithTimeIntervalSince1970:[timeSp floatValue]];
return [formatter stringFromDate:date];
}
+ (NSString *)md5:(NSString *)str
{
const char *cStr = [str UTF8String];
unsigned char result[16];
CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
@end
@@ -57,7 +57,7 @@
if (_passwordTextField.text.length>0 && _phoneNum.length>0) {
[MBProgressHUD hudWithView:self.view label:@"安全加载中"];
DaiDaiTongTestApi* daiDaiTongTestApi = [DaiDaiTongTestApi shareInstance];
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:_phoneNum,@"phoneNum",_passwordTextField.text, @"loginPsw", nil] withApiType:@"loginByPsw" completionBlock:^(id jsonRes) {
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:_phoneNum,@"phoneNum",[ManagerUtil md5:_passwordTextField.text], @"loginPsw", nil] withApiType:@"loginByPsw" completionBlock:^(id jsonRes) {
if (!([[jsonRes objectForKey:@"resultflag"] integerValue] == 0)) {
[MBProgressHUD errorHudWithView:self.view label:[jsonRes objectForKey:@"resultMsg"] hidesAfter:0.5];
@@ -28,6 +28,7 @@
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if (_type == 0) {
self.navigationItem.title = @"设置登录密码";
}else{
@@ -118,13 +119,15 @@
if (_type == 0 ) {
DaiDaiTongTestApi* daiDaiTongTestApi = [DaiDaiTongTestApi shareInstance];
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:_passWordTextField.text,@"loginPsw", nil] withApiType:@"setLoginPsw" completionBlock:^(id jsonRes) {
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:[ManagerUtil md5:_passWordTextField.text],@"loginPsw", nil] withApiType:@"setLoginPsw" completionBlock:^(id jsonRes) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
if (!([[jsonRes objectForKey:@"resultflag"] integerValue] == 0)) {
[MBProgressHUD errorHudWithView:self.view label:[jsonRes objectForKey:@"resultMsg"] hidesAfter:0.5];
}else{
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
[self.navigationController popViewControllerAnimated:YES];
}
} failedBlock:^(NSError *error) {
@@ -132,8 +135,10 @@
}];
}else{
DaiDaiTongTestApi* daiDaiTongTestApi = [DaiDaiTongTestApi shareInstance];
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:_passWordTextField.text,@"tradePsw", nil] withApiType:@"setTradePsw" completionBlock:^(id jsonRes) {
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:[ManagerUtil md5:_passWordTextField.text],@"tradePsw", nil] withApiType:@"setTradePsw" completionBlock:^(id jsonRes) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
if (!([[jsonRes objectForKey:@"resultflag"] integerValue] == 0)) {
[MBProgressHUD errorHudWithView:self.view label:[jsonRes objectForKey:@"resultMsg"] hidesAfter:0.5];
}else{
@@ -18,26 +18,26 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="line" placeholder="设置密码" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="qes-Vw-q4F">
<rect key="frame" x="20" y="75" width="280" height="44"/>
<rect key="frame" x="20" y="28" width="280" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="line" placeholder="密码确认" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="s3w-SU-YZd">
<rect key="frame" x="20" y="156" width="280" height="44"/>
<rect key="frame" x="20" y="109" width="280" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="密码由6-16个字符组成,字母区分大小写" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="0Ee-ib-6T6">
<rect key="frame" x="20" y="127" width="280" height="21"/>
<rect key="frame" x="20" y="80" width="280" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mWs-sA-ia8">
<rect key="frame" x="20" y="232" width="280" height="42"/>
<rect key="frame" x="20" y="171" width="280" height="42"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<state key="normal" title="完成">
@@ -51,7 +51,6 @@
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
</view>
</objects>
@@ -54,7 +54,7 @@
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
</view>
<view alpha="0.5" contentMode="scaleToFill" id="MKf-vY-jQ4">
<rect key="frame" x="10" y="89" width="300" height="1"/>
<rect key="frame" x="10" y="88" width="300" height="1"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
</view>
@@ -7,7 +7,7 @@
//
#import "AccountInfoViewController.h"
#import "SetPassWordViewController.h"
@interface AccountInfoViewController ()
{
NSDictionary* _infoDic;
@@ -30,8 +30,11 @@
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationItem.title = @"账户中心";
_tableView.delegate = self;
_tableView.dataSource = self;
[_topBtn addTarget:self action:@selector(modifyLoginPassword:) forControlEvents:UIControlEventTouchUpInside];
[_bottomBtn addTarget:self action:@selector(modifyTransactionsPassword:) forControlEvents:UIControlEventTouchUpInside];
[self loadData];
}
-(void)loadData
@@ -166,9 +169,16 @@
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
-(void)modifyPassword:(id)sender
-(void)modifyLoginPassword:(id)sender
{
DLog(@"点击");
SetPassWordViewController* setPassWordViewController = [[SetPassWordViewController alloc] init];
[self.navigationController pushViewController:setPassWordViewController animated:YES];
}
-(void)modifyTransactionsPassword:(id)sender
{
SetPassWordViewController* setPassWordViewController = [[SetPassWordViewController alloc] init];
setPassWordViewController.type = 1;
[self.navigationController pushViewController:setPassWordViewController animated:YES];
}
- (void)didReceiveMemoryWarning
{
@@ -47,7 +47,6 @@
#pragma mark UITextFieldDelegate
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
@@ -87,7 +86,7 @@
[MBProgressHUD hudWithView:self.view label:@"安全加载中"];
DaiDaiTongTestApi* daiDaiTongTestApi = [DaiDaiTongTestApi shareInstance];
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:_amount],@"amount", _passwordTextField.text,@"tradePsw",_proId, @"proId", nil] withApiType:@"buyProduct" completionBlock:^(id jsonRes) {
[daiDaiTongTestApi getApiWithParam:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:_amount],@"amount", [ManagerUtil md5:_passwordTextField.text],@"tradePsw",_proId, @"proId", nil] withApiType:@"buyProduct" completionBlock:^(id jsonRes) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
if ([[jsonRes objectForKey:@"resultflag"] integerValue] == 1) {
@@ -241,10 +241,25 @@
}
-(void)logout
{
[ManagerUser shareInstance].isLogin = false;
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[app.mainViewController setSelectedIndex:0];
[_tableView reloadData];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"确定退出吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"退出登录", nil];
[alertView show];
}
#pragma mark UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[ManagerUser shareInstance].isLogin = false;
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[app.mainViewController setSelectedIndex:0];
[_tableView reloadData];
DaiDaiTongTestApi* daiDaiTongTestApi = [DaiDaiTongTestApi shareInstance];
[daiDaiTongTestApi getApiWithParam:nil withApiType:@"logout" completionBlock:^(id jsonRes) {
} failedBlock:^(NSError *error) {
}];
}
}
- (void)didReceiveMemoryWarning
{