I am trying to implement a system in which a player can register, play and get points. How to make the balance of points that is stored in his account, could not hack the player himself or another player? Does it have to be restrictions in the code or in the database? I have a database, but the rules are set by default, it seems to me that they need to be changed.
Code entry points in the database as follows:
import Foundation import UIKit import Firebase import FirebaseDatabase let ref = Database.database().reference() let userID : String = (Auth.auth().currentUser?.uid)! class GameCoins: UIViewController, UnityAdsDelegate { @IBOutlet weak var currencyLabel: UILabel! override func viewDidLoad() { ref.child("users").child(userID).observeSingleEvent(of: .value, with: { (snapshot) in // Get user value let snapshotValue = snapshot.value as? NSDictionary let balance = snapshotValue!["coins"] as! Int self.currencyLabel.text = "\(String(describing: balance))" }) { (error) in print(error.localizedDescription) } super.viewDidLoad() } func gameMoveDidFinish(_ placementId: String) { if (state != .skipped) { ref.child("users").child(userID).observeSingleEvent(of: .value, with: { (snapshot) in // Get user value let snapshotValue = snapshot.value as? NSDictionary var balance = snapshotValue!["coins"] as! Int balance += 1 ref.root.child("users").child(userID).updateChildValues(["coins": balance]) self.currencyLabel.text = "\(String(describing: balance))" }) { (error) in print(error.localizedDescription) } } } } The base and rules are listed below: 
{ "rules": { ".read": "auth != null", ".write": "auth != null" } } I know that if you store points in NSUserDefaults, they can be easily cracked, so they use keychain. I get to store data on Firebase, but in the subject which should put a limit on writing and reading I understand very bad. I would be grateful for any recommendations and amendments, I want to figure out how to ensure the security of both the player and the application from hacking.