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

相关文章

SpringBoot中@Value注入静态变量方式

《SpringBoot中@Value注入静态变量方式》SpringBoot中静态变量无法直接用@Value注入,需通过setter方法,@Value(${})从属性文件获取值,@Value(#{})用... 目录项目场景解决方案注解说明1、@Value("${}")使用示例2、@Value("#{}"php

SpringBoot分段处理List集合多线程批量插入数据方式

《SpringBoot分段处理List集合多线程批量插入数据方式》文章介绍如何处理大数据量List批量插入数据库的优化方案:通过拆分List并分配独立线程处理,结合Spring线程池与异步方法提升效率... 目录项目场景解决方案1.实体类2.Mapper3.spring容器注入线程池bejsan对象4.创建

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

使用shardingsphere实现mysql数据库分片方式

《使用shardingsphere实现mysql数据库分片方式》本文介绍如何使用ShardingSphere-JDBC在SpringBoot中实现MySQL水平分库,涵盖分片策略、路由算法及零侵入配置... 目录一、ShardingSphere 简介1.1 对比1.2 核心概念1.3 Sharding-Sp

Spring创建Bean的八种主要方式详解

《Spring创建Bean的八种主要方式详解》Spring(尤其是SpringBoot)提供了多种方式来让容器创建和管理Bean,@Component、@Configuration+@Bean、@En... 目录引言一、Spring 创建 Bean 的 8 种主要方式1. @Component 及其衍生注解

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py

Linux系统管理与进程任务管理方式

《Linux系统管理与进程任务管理方式》本文系统讲解Linux管理核心技能,涵盖引导流程、服务控制(Systemd与GRUB2)、进程管理(前台/后台运行、工具使用)、计划任务(at/cron)及常用... 目录引言一、linux系统引导过程与服务控制1.1 系统引导的五个关键阶段1.2 GRUB2的进化优

Unity新手入门学习殿堂级知识详细讲解(图文)

《Unity新手入门学习殿堂级知识详细讲解(图文)》Unity是一款跨平台游戏引擎,支持2D/3D及VR/AR开发,核心功能模块包括图形、音频、物理等,通过可视化编辑器与脚本扩展实现开发,项目结构含A... 目录入门概述什么是 UnityUnity引擎基础认知编辑器核心操作Unity 编辑器项目模式分类工程

IDEA与MyEclipse代码量统计方式

《IDEA与MyEclipse代码量统计方式》文章介绍在项目中不安装第三方工具统计代码行数的方法,分别说明MyEclipse通过正则搜索(排除空行和注释)及IDEA使用Statistic插件或调整搜索... 目录项目场景MyEclipse代码量统计IDEA代码量统计总结项目场景在项目中,有时候我们需要统计

C#和Unity中的中介者模式使用方式

《C#和Unity中的中介者模式使用方式》中介者模式通过中介者封装对象交互,降低耦合度,集中控制逻辑,适用于复杂系统组件交互场景,C#中可用事件、委托或MediatR实现,提升可维护性与灵活性... 目录C#中的中介者模式详解一、中介者模式的基本概念1. 定义2. 组成要素3. 模式结构二、中介者模式的特点