Software authorization control, how does software control authorization?

Source: Internet
Author: User
Tags key string

Software authorization control, how does software control authorization?

For this app, because it integrates many motor performance tuning functions, we do not want every user to use it, especially competitors, therefore, only internal staff and customers of the company can get our authorization to experience and adjust our motor.

So what is the software authorization mechanism?

  • Request code Generation:

    Get an integer between 0 and X-1 through arc4random () % x.

    For more detail: www.cnblogs.com/xuling/archive/2012/02/28/2370692.html

  • Generate an 8-digit random application code:

NSMutableString requestCode = [NSMutableString stringWithCapacity: 8];

For (int I = 0; I <8; I ++ ){

Int a = arc4random () % 10;

[RequestCode appendString: [NSString stringWithFormat: @ "% I", a];

}

  • After the user gives the request code, we use a certain algorithm to calculate the product key and return it to the user;
  • The App also performs the same operation to obtain the product key for comparison with the product key entered by the user.
  • Use the NSUserDefaults object.

    NSUserDefaults is used to save and restore preference settings and configuration data related to applications.

[[NSUserDefaults standardUserDefault] setBool: YES forKey: @ "haveLicence"]; you can set a Bool value with the key "haveLicence.

[[NSUserDefaults standerdUserDefault] boolForKey: @ "haveLicence"]; you can get the Bool value of the key value "haveLicence.

Refer to: www.cnblogs.com/heyonggang/p/4253424.html

  • Use keychain.

    NSUserDefaults is just like a game archive. When the game is deleted, the archive is deleted. In order to allow users to obtain permanent authorization, they do not need to re-apply after the app is uninstalled and reinstalled. They need to use the keychain.

    Refer to: http://blog.k-res.net/archives/1081.html

  • Use the operation keychain in the ARC environment.

    The KeychainItemWrapper class officially provided by apple is not friendly to the ARC compiling environment.

    In this case, when the project is an ARC compiling environment, you can double-click the corresponding class file in Build Phases-Complie Sources and enter: -fno-objc-ARC.

    Refer to: www.cocoachina.com/ios/20140912/9605.html

    Unfortunately, my attempt has no effect. I have not found out the reason why it does not work. If any of you know it, I hope you will be notified and guided!

    Finally, I finally found an SSKeychain class, which encapsulated Apple's security framework API and supported access to passwords and Accounts stored in the key string, including reading, deleting, and setting.

    Refer to: http://my.oschina.net/u/736617/blog/225833

[SSKeychain setPassword: @ "haveLicence" forService: @ "VID" account: @ "ONE" error: nil]; in this way, the Service "VID" can be the name of the app, or the name of an operation or task.) for the account: "ONE", SET password: "haveLicense ".

 

NSString password = [[SSKeychain passwordForService: @ "VID" account: @ "ONE" error: nil.

 

In this app, the user is not required to set a password, but the data stored in the Keychain is not lost due to the deletion of the app. After the user is authorized, WRITE password: "haveLicence" to the Account "ONE ";

When the app is started, determine whether the password is haveLicence for permission control.

 

The above are the key points for simple software authorization in the app.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.