Simple iPhone Tutorial: Password Management using the keychain by using SFHFKeychainUtils

Keychain is really a pain to use, and I didn’t want to spend the time to figure it all out, so I went looking for a framework that would do the dirty work for me. I found SFHFKeychainUtils and it has been super slick! In this tutorial, I’ll show you how to leverage SFHFKeychainUtils in order to save a username/password to keychain and also retrieve the password given the username. Just follow these simple steps:

1. Get SFHFKeychainUtils

I found it on GitHub at http://github.com/ldandersen/scifihifi-iphone/tree/master/security/ – just get the SFHFKeychainUtils.h and SFHFKeychainUtils.m files and add them to your project.

2. Import it

In the implementation file where you want to save or retrieve the password, be sure you import the SFHF Keychain Utils header file as shown below:

#import “LoginViewController.h”
#import “SFHFKeychainUtils.h”
@implementation LoginViewController

3. Save a Username/Password

xCode SFHFKeychainUtils iPhone Keychain Example





Here you can see how simple it is to add the username/password to the iPhone’s keychain. The storeUsername:andPassword:forServiceName:updateExisting:error method will take care of all the work for us if we give it the correct parameters. I am getting the username and password from two UITextFields in the app called usernameField and passwordField, respectively. The Service Name can be anything you want, as long as you remember it as you’ll need to enter that same string value in order to retrieve the password (see step 4).

4. Retrieve the Password from Keychain

xCode SFHFKeychainUtils iPhone Keychain Example




As you can see, it’s not any more difficult to retrieve the password from keychain using SFHFKeychainUtils. I specified my username “Gorgando” and the same service name we used before “myApp”. The password that corresponds to this username and service name in the keychain will be returned as an NSString.

So don’t be afraid to use the keychain! It is the most secure way to store passwords in an iPhone application. Both plists and the Settings.Bundle are very insecure ways to store passwords because the passwords are stored in plaintext, visible to anyone who accesses them. Let me know if you have any questions – good luck!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
分数阶微分方程是一类比常见的线性微分方程更为复杂的方程,其被广泛应用于物理、生物、金融等领域。本文将介绍如何使用MATLAB编写解决分数阶微分方程的代码。 首先,将分数阶微分方程转化为常微分方程。这可以通过采用Caputo定义,或者Grünwald-Letnikov定义加权平均来实现。在这里,我们采用Caputo定义将分数阶微分方程转化为常微分方程。 接下来,我们可以使用MATLAB中的ode45函数解决常微分方程。ode45是一种常用的解决常微分方程的函数,它可以在一定时间范围内对微分方程进行数值解。 代码演示: % 定义分数阶微分方程 y(t) function dydt = fractional_deriv(t,y,alpha) dydt = zeros(1,1); dydt(1) = Caputo_derivative(y,alpha); % 定义Caputo导数 function result = Caputo_derivative(y,alpha) syms t p; f = laplace(y,t,p); result = real(ilaplace((p^alpha)*f,p,t)); % 定义初始值 y0 = 0.5; % 定义时间范围 tspan = [0 10]; % 定义分数阶参数 alpha = 0.5; % 使用ode45函数解决微分方程 [t,y] = ode45(@(t,y)fractional_deriv(t,y,alpha),tspan,y0); % 打印结果 plot(t,y); 在以上代码示例中,我们定义了分数阶微分方程和Caputo导数,然后使用ode45函数来解决得到结果。最后,我们绘制了图形以分析解决方案的有效性。 在MATLAB中解决分数阶微分方程并不困难,只要有一定的编程基础和问题领域的背景知识,就可以轻松地解决分数阶微分方程问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值