Stop Putting Secrets in Your Code! Store PINs and Tokens with Script Properties
Form PINs, bot tokens and API keys don't belong in your code. Here's a simple way to store them more safely.
Kumron Boonget2 Dec 2026 · 1 min read
Many people write this in their code:
const PIN = '1234';
const TOKEN = '123456:ABC-xyz';It works, but anyone who can view the code, or anyone you send it to for help, sees the secrets immediately. A better way is to keep them in Script Properties.
What are Script Properties?
They are name = value pairs stored with your Apps Script project. They are not part of your code files, so when you copy and share the code, they don't go with it.
How to set them
- In the Apps Script editor, click the gear icon (Project Settings)
- Scroll down to Script Properties → Add script property
- Enter a name such as
FORM_PINand a value such as482913 - Click Save script properties
Use them in your code
function checkPin(pin) {
const real = PropertiesService.getScriptProperties().getProperty('FORM_PIN');
if (!real) throw new Error('FORM_PIN is not set');
if (String(pin) !== real) throw new Error('Incorrect PIN');
return true;
}Tip Always send the PIN from the form to the server side (Code.gs) to check it. Never check the PIN in the HTML page, because anyone can view the page source.
Summary
| In your code | In Script Properties |
|---|---|
| Visible every time the code is opened | Not in the code files |
| Copied along when you share the code | Not copied along |
| Changing it means editing code and redeploying | Change it instantly, no redeploy |
That last point is really handy: you can change the PIN right away without touching the code.
Comments
No comments yet. Be the first to share your thoughts or ask a question.
Read next
Build a Search Page for Your Google Sheets Data with Apps Script in 15 Minutes
Turn a sheet with thousands of rows into a simple web page where anyone on your team can type and find what they need, without opening the sheet.
Send Automatic Telegram Alerts When a New Row Is Added in Google Sheets
Whenever someone submits a form or adds a new job to your sheet, get a Telegram notification right away instead of checking the sheet yourself.