American Express Interview Question

How to make this code secure based on a use case?