pass2word例子---------------启动密码存储


设置密码

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #pragma mark-- switch change  
  2. - (void)switchChanged:(id)sender  
  3. {  
  4.     if (_passwordProtect.on == NO)  
  5.     {  
  6.         _passwordProtectAlertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"确定取消主密码保护吗? 唤醒应用不再需要密码!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil nil];  
  7.         [_passwordProtectAlertView show];  
  8.     }  
  9.     else  
  10.     {  
  11.         _setPasswordAlertView = [[UIAlertView alloc] initWithTitle:@"请输入密码:" message:@"\n" delegate:self cancelButtonTitle:@"取消"  
  12.                otherButtonTitles:@"确定", nil nil];  
  13.         _setPasswordAlertView.alertViewStyle = UIAlertViewStyleSecureTextInput;  
  14.           
  15.         [_setPasswordAlertView show];  
  16.           
  17.     }  
  18. }  
  19.   
  20. #pragma mark-- alert delecate  
  21. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  22. {  
  23.     if (alertView == _passwordProtectAlertView)  
  24.     {  
  25.         switch (buttonIndex)  
  26.         {  
  27.                 //确定  
  28.             case 0:  
  29.                 _islk = NO;  
  30.                 break;  
  31.                 //取消  
  32.             case 1:  
  33.                 [_passwordProtect setOn:YES animated:YES];  
  34.                 break;  
  35.             default:  
  36.                 break;  
  37.         }  
  38.     }  
  39.     else if(alertView == _setPasswordAlertView )  
  40.     {  
  41.         if (buttonIndex == 0)  
  42.         {  
  43.             [_passwordProtect setOn:NO animated:YES];  
  44.         }  
  45.         else  
  46.         {  
  47.             NSString *pwd = [_setPasswordAlertView textFieldAtIndex:0].text;  
  48.             if ([pwd length])  
  49.             {  
  50.                 //save password  
  51.                 [[NSUserDefaults standardUserDefaults] setObject:pwd forKey:@"mainpassword"];  
  52.                 [[NSUserDefaults standardUserDefaults] synchronize];  
  53.                 _islk = YES;  
  54.   
  55.             }  
  56.             else  
  57.                 [_passwordProtect setOn:NO animated:YES];  
  58.         }  
  59.     }  
  60.     [[NSUserDefaults standardUserDefaults] setBool:_islk forKey:@"islocked"];  
  61.     [[NSUserDefaults standardUserDefaults] synchronize];  
  62. }  



获取密码

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. - (IBAction)login:(id)sender  
  2. {  
  3.     NSString *pswd = [[NSUserDefaults standardUserDefaults] objectForKey:@"mainpassword"];  
  4.     if([_passwordTextField.text isEqualToString:pswd])  
  5.         [self.presentingViewController dismissViewControllerAnimated:NO completion:nil];  
  6.     else  
  7.     {  
  8.         UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"警告" message:@"密码错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil];  
  9.         [alertV show];  
  10.     }  
  11.     _passwordTextField.text = @"";  
  12. }  
### 配置和访问 OnlyOffice 文档服务器 URL 的方法 要正确配置并访问 OnlyOffice 文档服务器的 URL,需关注以下几个核心方面: #### 1. **设置文档服务器的基础地址** `documentServerUrl` 是指明在线编辑文档服务器的具体地址(包括 IP 和端口)。该地址应指向实际部署的 OnlyOffice 文档服务器实例。例如,如果文档服务器运行在 `http://example.com:8080` 上,则需要将其配置为: ```javascript { "documentServerUrl": "http://example.com:8080" } ``` 这一步骤确保前端应用能够找到对应的文档服务器位置[^2]。 #### 2. **定义唯一的文档标识符 (Key)** 为了提高性能和安全性,在每次请求文档时都需要生成一个新的唯一标识符 (`config.document.key`)。这个键可以基于文档的实际 URL 或其他自定义逻辑生成,但需要注意以下几点: - 不得超过 128 个字符。 - 禁止使用特殊字符。 示例代码展示如何动态生成 Key 值: ```python import hashlib def generate_document_key(document_url): hash_object = hashlib.md5(document_url.encode()) return hash_object.hexdigest()[:128] # 使用示例 url = "http://your-storage-service/file.docx" key = generate_document_key(url) print(key) ``` #### 3. **指定源文档的绝对 URL** `config.document.url` 属性用于描述存储原始文档的位置。通常情况下,这是一个由开发者自行编写的接口来返回文件流的内容。以下是 Java 实现的一个简单例子: ```java @RestController @RequestMapping("/api/files") public class FileController { @GetMapping("/{fileName}") public ResponseEntity<Resource> getFile(@PathVariable String fileName) throws IOException { Path path = Paths.get("/path/to/your/documents/" + fileName); Resource resource = new UrlResource(path.toUri()); if (!resource.exists()) { throw new FileNotFoundException("File not found"); } return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"") .body(resource); } } ``` 上述代码片段展示了如何通过 RESTful API 提供文件下载功能。 #### 4. **配置回调地址以保存修改后的文档** 当用户完成对文档的操作后,OnlyOffice 将调用预设好的回调地址 (`config.editorConfig.callbackUrl`) 来通知您的系统更新相应的文件副本。下面是一个 Python Flask 应用程序接收回调数据的例子: ```python from flask import request, jsonify, Flask app = Flask(__name__) @app.route('/callback', methods=['POST']) def handle_callback(): data = request.json file_url = data['url'] # 获取上传的新版本文件链接 # 处理业务逻辑... return jsonify({"status": "success"}), 200 if __name__ == '__main__': app.run(debug=True) ``` #### 5. **测试连接与优化加载速度** 对于某些场景下遇到的加载缓慢问题,可能涉及网络延迟或者资源未被有效压缩传输等原因。建议检查 Nginx/Apache 配置中的静态资源缓存策略以及启用 Gzip 压缩支持[^1]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MyObject-C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值