iOS-account password autofill and add

iOS-account password autofill and add

foreword

This function has been launched for a long time, and this function has been implemented in many APPs. Today, I found that this function is very friendly and the APP in hand has not yet implemented this function. I simply review and record it.

Password AutoFill simplifies login and account creation tasks for iOS apps and web pages. With just a few taps, your users can create and save new passwords or log into existing accounts. Users don't even need to know their passwords; the system handles everything. This convenience increases the likelihood that users will complete the application login or registration process and start using your application faster. Additionally, you can increase the security of your app by encouraging users to choose unique, strong passwords. By default, Password AutoFill saves the user's login credentials on their current iOS device. iOS can securely sync these credentials across a user's devices using iCloud Keychain . Password autofill only recommends credentials for the app's associated domain, and users must authenticate with Face ID or Touch ID before accessing those credentials . For more information on privacy and security, see Privacy Methods and iOS Security Guidelines . Password AutoFill also provides credentials for third-party password managers that implement credential provider extensions. For more information on credential provider extensions, see AuthenticationServices Framework.

Password Autofill uses heuristics to determine when a user logs in or creates a new password, and automatically provides the password QuickType bar. These heuristics provide users with some password autofill support in most apps, even if those apps haven't been updated to support autofill. However, to provide the best user experience and ensure that your app fully supports password autofill, you need to associate a domain name in your app and set the correct type in the input box. The condition for triggering autofill is that the user clicks the input view and clicks the autofill button in the keyboard. If the user installs the APP, the system will associate the application with the application domain name list and obtain each domain from the Associated Domains Entitlement , and will try to download the Apple App Site Association file of the domain . If the above steps are successful, the system will associate the application with the The domain is associated and password autofill is enabled for the domain's credentials. The use of account and password autofill requires the system to be on iOS11.0 and higher systems, and iOS10.0 and above systems have accounted for 90%+, so it is necessary for us to provide a better experience and help users quickly Log in.

Operating procedures:

①Enable Associated Domains in the project , or open it in the project configuration file in the Apple background. The demo in this article is an automatic signature. After opening and running the project, you will find that there will be a key pattern above the keyboard after clicking the input box, you can click to select the specified account and password to proceed. Fill in the input box.

 

 

 

Clicking the Add button will directly add one  webcredentials:example.com, and the official format is: <service>:<fully qualified domain>:<port number>. The webcredentials in the picture is a service for web pages and applications to share certificates, as follows:

applinks: 通用链接服务
webcredentials:网页和应用共享证书凭据服务
activitycontinuation:HandOff服务
复制代码

If the website needs to adapt to the subdomain name of example.com, then yes .example.com, and ensure that each added item should have a webcredentials:  header.

② Create a file: apple-app-site-association  where 24GJHXXX is teamID , not the ID on the certificate. In addition, the latter is the BundleID of the app , so the format is: <teamID>.<BundleID>, if there are more than one, they can be added in the array. And make sure that the file json format is correct.

{
    "webcredentials": {
        "apps": ["24XGJHXXX.cn.mypup.PasswordFillDemo"]
    }
}
复制代码

③Ensure that the file is uploaded to the directory or folder of the domain name filled in in ① .well-know, the official recommended folder, and ensure that the file can be accessed by https :https://example.com/.wellhnow/apple-app-site-association

④In Xib or code, fill in the textContentType of the input box as .usernameand.password

 

 

 

⑤In the [Settings]-[Password and Account]-Website and App Password]-create a new account and password for the specified website in the mobile phone, and then run the APP, click on the input box and you will find that it is different from the time in ①, and it directly shows us For the set account, click to fill in the account and password, and when you click the key icon, it also displays the account list of the website and has the option to select other accounts. This is the same experience as QQ and other apps that support autofill.

 

 

 

 

 

 

Add account password

In other words, if the user is allowed to add the account password, it is not very convenient to fill it in. The normal logic should be that we save the account password when we register and log in successfully. The subsequent login can directly use the autofill to log in. It is the most convenient. This Apple I also thought that you can add accounts to shared credentials. The following is to add the entered account to the keychain and synchronize it with iCloud. This account can be used across devices to fill.

let server = "mypup.cn"
let user = User.init(user: userTextField.text ?? "", password: passwordTextField.text ?? "")
SecAddSharedWebCredential(server as CFString, user.user as CFString, user.password as 	
CFString) { (error) in
    guard error == nil else {
         print("发生错误", error!.localizedDescription)
         return
    }
    print("存储新账号密码成功")
}
复制代码

The above code will pop up a prompt to ask the user whether to allow saving. After the user agrees, this account can be used to fill in the device and other devices and browsers that have logged in with the same ID.

 

 

 

Summarize

Use Apple iOS11 to introduce the password auto-fill function to simplify the user's login operation. Among them, textContentType has many features. Through iCloud and HandOff, an excellent cross-device experience can be achieved. In addition, this article does not mention the part of generating strong passwords, because few people in China use this function, at least I do, for fear of forgetting the password or logging in on other terminals without knowing the embarrassment of the password, Apple provides strong password generation according to the specified It is still very convenient for foreigners to generate rules.

Reprinted from Author: Happy Xiao Muzi
Link: https://juejin.im/post/5d2450e651882555300feb4d

Guess you like

Origin blog.csdn.net/ForeverMyheart/article/details/117320925