Security Requirements of a Database

A secure database needs: physical database integrity (survives power failure and disasters), logical database integrity (the structure is preserved), element integrity (values are correct), auditability (changes can be traced), access control, user authentication, and availability. These match the CIA aims for data.

Reliability and Integrity

  • Entity integrity: every row has a unique, non-null primary key.
  • Referential integrity: a foreign key must match an existing primary key (no order for a customer that does not exist).
  • Domain and check constraints: values must be of the allowed type and range.
  • Transactions with ACID properties:Atomicity (all or nothing), Consistency, Isolation (concurrent transactions do not interfere) and Durability (committed data survives failure).
  • Two-phase update: an intent phase and a commit phase, so a failure in between can be repaired.
  • Redundancy and recovery:backups, logs, mirroring and error-correcting codes, and concurrency control with locks.

Sensitive Data

Sensitive data is data that must not be disclosed freely: personal identifiers, health, financial and academic records, passwords and trade secrets. It may be sensitive because of its nature, its source, its declared status or its relation to other data. Protection options: classify data, restrict access, mask (show only the last four digits), tokenise, pseudonymise or anonymise, and apply the disclosure rules of the law (see Unit IV). Passwords are not stored but kept as salted, slow hashes (for example PBKDF2, bcrypt, scrypt or Argon2).

Database Encryption

Encrypting the stored data protects it if the files, disk or backup are stolen. Levels: whole disk or file encryption, transparent data encryption inside the DBMS, column-level encryption of selected fields, and application-level encryption. Data in transit uses TLS. Key points: key management (keep keys away from the data, rotate them), the cost to performance, and the difficulty of searching or indexing encrypted columns, since equal values may need equal ciphertext. Encryption does not stop a legitimate but over-privileged user.

Definition: ACID. The four properties of a reliable database transaction: Atomicity, Consistency, Isolation and Durability.

Table 2.5: Database integrity rules

Integrity Rule Example
Entity Unique, non-null primary key Every student has a roll number
Referential Foreign key matches a primary key An order refers to an existing customer
Domain Value within allowed range Marks between 0 and 100
Atomicity Transaction is all or nothing Debit and credit both happen or neither

Example 2.5: Salted password hashing

Problem: Two users choose the same password, pass123. The database stores a 16-byte random salt and the PBKDF2-SHA256 hash (100,000 iterations) for each. Will their stored hashes be equal? How long is each hash in hexadecimal, and does verification work?

Solution:

  1. Each user has a different random salt, so the hash input differs even for the same password.
  2. Therefore the two stored hashes are not equal.
  3. The hash is 32 bytes (256 bits), which is 64 hexadecimal characters.
  4. To verify, hash the typed password with the stored salt and compare with the stored hash; the correct password matches.

Result: The hashes differ (False), each is 64 hex characters, and a login with the right password and the stored salt is accepted (True).

import hashlib
import os
pw = b"pass123"
s1, s2 = os.urandom(16), os.urandom(16)
h1 = hashlib.pbkdf2_hmac("sha256", pw, s1, 100000)
h2 = hashlib.pbkdf2_hmac("sha256", pw, s2, 100000)
print("Hex length:", len(h1.hex()))
print("Same hash for same password:", h1 == h2)
again = hashlib.pbkdf2_hmac("sha256", pw, s1, 100000)
print("Login accepted:", again == h1)

Output

Hex length: 64
Same hash for same password: False
Login accepted: True

Common mistakes

  • Storing passwords in plain text or with an unsalted fast hash.
  • Keeping the encryption key in the same place as the encrypted data.
  • Skipping integrity constraints and trusting the application alone.
  • Believing that encryption removes the need for access control.

Key takeaways

  • Requirements: physical, logical and element integrity, audit, access control, availability.
  • Entity, referential and domain integrity; ACID transactions.
  • Protect sensitive data by classification, masking and anonymisation.
  • Encrypt at rest and in transit; manage keys carefully; hash passwords with a salt.

Practice questions

  1. What does ACID stand for?
  2. What is referential integrity?
  3. Why is a salt used when hashing passwords?

Answers to the practice questions

  1. Atomicity, Consistency, Isolation and Durability.
  2. A foreign key must match an existing primary key.
  3. So that equal passwords give different hashes and precomputed tables fail.

Sources

  • Official BCA syllabus Computer Security, course code 25BCA406DS02, Unit II