IOS学习之IOS端账号密码登入和后台校验方式

2024-05-26 12:38

本文主要是介绍IOS学习之IOS端账号密码登入和后台校验方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这里先列出server后台对登入的方法验证:

<struts><package name="system-remote" extends="default" namespace="/common/open"><action name="login" class="net.zdsoft.eis.remote.RemoteAppLoginAction"method="login" /></package>
</struts>

//移动端参数private String parm;public void login() throws Exception {JSONObject json = getJsonParam();boolean permission=true;String username = json.getString("username");String pwd = json.getString("pwd");parm = getParamValue("parm");try {String ispermission = json.getString("permission");if(StringUtils.isNotBlank(ispermission) && "false".equals(ispermission)){permission=false;}} catch (Exception e) {}User user = null;Account account = null;String errorMsg = null;if (isEisDeploy()) {try {user = userService.getUserByUserName(username);} catch (Exception e) {errorMsg = "取用户信息出错: " + e.getMessage();}} else {account = baseDataSubsystemService.queryAccountByUsername(username);if (account != null) {String accountId = account.getId();user = userService.getUserByAccountId(accountId);user.setPassword(account.getPassword());}}String password = null;if (null != user) {/** password城域库中密码, pwd为用户输入密码 * */password = user.findClearPassword();if ("".equals(password)) {password = null;}}int result;// 1:用户名密码正确;-1:用户名不存在;-2:密码错误;-3:用户状态不正常if (null == user || user.getName() == null) {result = -1;} else if (user.getMark() == null|| user.getMark() != User.USER_MARK_NORMAL) {result = -3;// 用户状态不正常(如: 未审核,锁定等)} else if ((password == null && (StringUtils.isBlank(pwd)))|| pwd.equals(password)) {result = 1;} else {result = -2;}// 用户校验正常情况下还需校验其所属单位信息是否正常if (result == 1) {Unit unit = unitService.getUnit(user.getUnitid());if (unit == null || unit.getIsdeleted()) {errorMsg = "用户所属单位信息不存在或已经删除!";} else {int mark = unit.getMark().intValue();if (Unit.UNIT_MARK_NORAML != mark) {errorMsg = "用户所属单位信息未审核或已锁定!";}// 报送单位if (null == unit.getUsetype()) {errorMsg = "用户所属单位信息的报送类别为空!";}}} else if (result == -3) {errorMsg = "该账号未审核或已锁定,请联系单位管理员或上级单位管理员!";} else {errorMsg = "账号或密码错误,请重新输入!";}if (StringUtils.isBlank(errorMsg)) {AppLoginUser loginUser = initLoginUser(user,permission);sendResult(RemoteCallUtils.convertJson(loginUser).toString());} else {sendResult(RemoteCallUtils.convertError(errorMsg).toString());}}
public static final String JSON_PARAM = "params";
/*** 取得经过解析后的返回参数* @return*/public JSONObject getJsonParam() {if (jsonParam != null)return jsonParam;JSONObject jsonv = getJson();if (jsonv.containsKey(RemoteCallUtils.JSON_PARAM)) {jsonParam = jsonv.getJSONObject(RemoteCallUtils.JSON_PARAM);}else {jsonParam = new JSONObject();}return jsonParam;}


/*** 取得返回的原始参数* @return*/public JSONObject getJson() {if (json != null)return json;String param = getRemoteParam();param = RemoteCallUtils.decode(remoteParam);if (StringUtils.isBlank(param)) {return new JSONObject();}try {json = JSONObject.fromObject(param);return json;}catch (Exception e) {return new JSONObject();}}

<pre name="code" class="java">RemoteCallUtils.java 类中的方法
 
/*** 内容进行解密以及反编码压缩* * @param s* @return*/public static String decode(String s) {// MD5加密先去掉// String md5 = StringUtils.substring(s, 0, 32);String zips = ZipUtils.unzipDecode(StringUtils.substring(s, 32));// String checkMd5 =// SecurityUtils.encodeByMD5(SecurityUtils.encodeByMD5(zips) + zips);// if (StringUtils.equals(md5, checkMd5)) {// return zips;// }// else {// return "";// }return zips;}
ZipUtils类中的方法
public static String unzipDecode(String encode) {byte[] bs;try {bs = Base64.decodeBase64(encode);Inflater decompressor = new Inflater();decompressor.setInput(bs);ByteArrayOutputStream bos = new ByteArrayOutputStream(bs.length);byte[] buf = new byte[1024];buf = new byte[1024];while (!decompressor.finished()) {int count = decompressor.inflate(buf);if (count <= 0)break;bos.write(buf, 0, count);}bos.close();byte[] decompressedData = bos.toByteArray();return new String(decompressedData, "utf8");}catch (Exception e) {e.printStackTrace();}return null;}

IOS移动端发送账号密码进行校验

#pragma mark - 登录的代理方法
-(void) doLoginWithUserName:(NSString *)userName password:(NSString *) pwd
{if ([userName isEqualToString:@""]) {// 用户名不能为空[MessageTool showMessage:@"请输入用户名"];return;}if ([pwd isEqualToString:@""]) {// 密码不能为空[MessageTool showMessage:@"请输入密码"];return;}//NSLog(@"用户名:%@ 密码:%@",userName, pwd);NSMutableDictionary *params = [NSMutableDictionary dictionary];//param: {username:’登陆账号’, pwd:’密码’, parm:’office_mobile’}params[kParamKeyUserName] = userName;params[kParamKeyUserPwd] = pwd;params[kParamKeyMobileParam] = @"office_mobile";NSURL *loginUrl = [HttpTool getActionUrl: @"common/open/login.action"];[HttpTool method:@"GET" url:loginUrl params:params success:^(id JSON) {NSDictionary *dic = (NSDictionary *)JSON;if ([dic[kJSON_RESULT_STATUS] integerValue] == JSON_STATUS_SUCCESS) {// 登录成功//保存帐号[[AccountSerive sharedAccountSerive] saveAccount:params];[AccountSerive sharedAccountSerive].currentUser = [[LoginUser alloc] initWithDict:dic];self.view.window.rootViewController = [[MainController alloc] init];} else {//登录失败[MessageTool showMessage:dic[kJSON_RESULT_STR]];}} failure:^(NSError *error) {[MessageTool showMessage:kHttpErrorMessage];}];}
HttpTool 方法中

+ (void)method:(NSString *)method url:(NSURL *)url params:(NSDictionary *)params success:(HttpSuccessBlock)success failure:(HttpFailureBlock)failure
{NSURL *newUrl = [NSURL URLWithString:[RemoteCallTool dictToParamString:params] relativeToURL:url];NSLog(@"url=%@", [newUrl absoluteString]);if ([[method lowercaseString] isEqualToString:@"get"]) {[self GET:newUrl params:nil success:success failure:failure];} else {[self POST:newUrl params:nil success:success failure:failure];}}
RemoteCallTool类中方法中:

@implementation RemoteCallTool#pragma mark dict转nsstring 
+(NSString *) dictToParamString:(NSDictionary *) dictionary
{NSMutableString *params = [[NSMutableString alloc] init];[params appendString:@"?"];[params appendString:kPARAM_NAME];[params appendString:@"="];NSMutableDictionary * allParams = [NSMutableDictionary dictionary];allParams[kJSON_PARAM] = dictionary;allParams[kJSON_TASK_ID] = [self uuidString];NSError* error = nil;NSData* result = [NSJSONSerialization dataWithJSONObject:allParams options:kNilOptions error:&error];if (error != nil) {return nil;}[params appendString:[self encode:[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]]];// url中如果包含中文字符,需要转换成带百分号的格式return [params stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}#pragma mark 解码返回的HTTP response
+(id)decodeResponse:(NSData *)responseData
{NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];NSString *responseJson = [self decode:response];//NSLog(@"response:%@", responseJson);return [JsonTool jsonStringToObject:responseJson];
}+ (NSString *)uuidString
{CFUUIDRef uuid_ref = CFUUIDCreate(NULL);CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);NSString *uuid = [NSString stringWithString:(__bridge NSString *)uuid_string_ref];CFRelease(uuid_ref);CFRelease(uuid_string_ref);return [[uuid lowercaseString] stringByReplacingOccurrencesOfString:@"-" withString:@""];
}#pragma mark 加密字符串
+(NSString *) encode:(NSString *)str
{//NSString *str =@"{\"result_status\":-1,\"result_str\":\"参数不对!\"}";//@"eJyrVipKLS7NKYkvLkksKS1WstI11EEIFSlZKT3tb3o2dcOTHb1P1-98v6dRqRYAGEoXfw";NSData *zipeData =[CompressTool zlibCompressData:[str dataUsingEncoding:NSUTF8StringEncoding]];NSData *base64Data= [GTMBase64 webSafeEncodeData:zipeData padded:NO];NSString *encodedStr = [[NSString alloc] initWithData:base64Data  encoding:NSUTF8StringEncoding];NSString *selfMD5 = [[CryptoTool md5:str] stringByAppendingString:str];return [[CryptoTool md5:selfMD5] stringByAppendingString:encodedStr];
}








这篇关于IOS学习之IOS端账号密码登入和后台校验方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1004497

相关文章

MybatisPlus中几种条件构造器运用方式

《MybatisPlus中几种条件构造器运用方式》QueryWrapper是Mybatis-Plus提供的一个用于构建SQL查询条件的工具类,提供了各种方法如eq、ne、gt、ge、lt、le、lik... 目录版本介绍QueryWrapperLambdaQueryWrapperUpdateWrapperL

idea设置快捷键风格方式

《idea设置快捷键风格方式》在IntelliJIDEA中设置快捷键风格,打开IDEA,进入设置页面,选择Keymap,从Keymaps下拉列表中选择或复制想要的快捷键风格,点击Apply和OK即可使... 目录idea设www.chinasem.cn置快捷键风格按照以下步骤进行总结idea设置快捷键pyth

Linux镜像文件制作方式

《Linux镜像文件制作方式》本文介绍了Linux镜像文件制作的过程,包括确定磁盘空间布局、制作空白镜像文件、分区与格式化、复制引导分区和其他分区... 目录1.确定磁盘空间布局2.制作空白镜像文件3.分区与格式化1) 分区2) 格式化4.复制引导分区5.复制其它分区1) 挂载2) 复制bootfs分区3)

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

java敏感词过滤的实现方式

《java敏感词过滤的实现方式》文章描述了如何搭建敏感词过滤系统来防御用户生成内容中的违规、广告或恶意言论,包括引入依赖、定义敏感词类、非敏感词类、替换词类和工具类等步骤,并指出资源文件应放在src/... 目录1.引入依赖2.定义自定义敏感词类3.定义自定义非敏感类4.定义自定义替换词类5.最后定义工具类

python项目环境切换的几种实现方式

《python项目环境切换的几种实现方式》本文主要介绍了python项目环境切换的几种实现方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 如何在不同python项目中,安装不同的依赖2. 如何切换到不同项目的工作空间3.创建项目

SpringBoot的内嵌和外置tomcat的实现方式

《SpringBoot的内嵌和外置tomcat的实现方式》本文主要介绍了在SpringBoot中定制和修改Servlet容器的配置,包括内嵌式和外置式Servlet容器的配置方法,文中通过示例代码介绍... 目录1.内嵌如何定制和修改Servlet容器的相关配置注册Servlet三大组件Servlet注册详

C# WebAPI的几种返回类型方式

《C#WebAPI的几种返回类型方式》本文主要介绍了C#WebAPI的几种返回类型方式,包括直接返回指定类型、返回IActionResult实例和返回ActionResult,文中通过示例代码介绍的... 目录创建 Controller 和 Model 类在 Action 中返回 指定类型在 Action

SQL 注入攻击(SQL Injection)原理、利用方式与防御策略深度解析

《SQL注入攻击(SQLInjection)原理、利用方式与防御策略深度解析》本文将从SQL注入的基本原理、攻击方式、常见利用手法,到企业级防御方案进行全面讲解,以帮助开发者和安全人员更系统地理解... 目录一、前言二、SQL 注入攻击的基本概念三、SQL 注入常见类型分析1. 基于错误回显的注入(Erro

requests处理token鉴权接口和jsonpath使用方式

《requests处理token鉴权接口和jsonpath使用方式》文章介绍了如何使用requests库进行token鉴权接口的处理,包括登录提取token并保存,还详述了如何使用jsonpath表达... 目录requests处理token鉴权接口和jsonpath使用json数据提取工具总结reques