使用Apple Touch ID登录外部数据库

Mel*_*rne 0 ios touch-id swift

我有一个用Swift制作的iOS应用程序,这是一个小社交网络.用户可以使用登录/密码连接,我将其保存在私人服务器上的数据库中.我想实现TouchID以帮助他们更快地登录.但是,我的用户帐户未与其Apple ID相关联.

// Touch ID button has been clicked
func touchIDButtonClicked() {
    print("touchIDButtonClicked");

    //Is Touch ID hardware available & configured?
    if(authContext.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error:&error))
    {
        //Perform Touch ID auth
        authContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Connect to the network with your fingertips", reply: {(wasSuccessful:Bool, error:NSError?) in

            if(wasSuccessful)
            {
                //User authenticated
                print("OK");
                // Log the user
            }
            else
            {
                //There are a few reasons why it can fail, we'll write them out to the user in the label
                print("NO");
               // Tell the user to use his password
            }

        })

    }
}
Run Code Online (Sandbox Code Playgroud)

我正在寻找的概念解决方案不仅仅是技术解决方案.我已经研究过TouchID了.有人能帮我吗 ?

jca*_*ron 6

Touch ID不会识别某个人(它无法告诉您它是用户1还是用户2).它验证一个人(电话的所有者).

因此,您无法单独使用Touch ID登录.您可以使用它,避免输入相同的凭据.

所以它会像这样工作:

  1. 第一次,对于用户ID和密码,并进行常规登录
  2. 询问用户是否希望使用Touch Id进行访问.如果是这样,请安全地存储用户ID和密码(或者更好的是,引用用户的令牌).
  3. 然后,在随后使用应用程序时,不要询问用户ID和密码,只询问Touch ID,如果没有,则重新使用保存的凭据.否则回到1.