🇹🇭 อ่านฉบับภาษาไทย →

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 BoongetKumron Boonget
2 Dec 2026 · 1 min read

Many people write this in their code:

js
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

  1. In the Apps Script editor, click the gear icon (Project Settings)
  2. Scroll down to Script Properties → Add script property
  3. Enter a name such as FORM_PIN and a value such as 482913
  4. Click Save script properties

Use them in your code

js
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 codeIn Script Properties
Visible every time the code is openedNot in the code files
Copied along when you share the codeNot copied along
Changing it means editing code and redeployingChange it instantly, no redeploy

That last point is really handy: you can change the PIN right away without touching the code.

#Apps Script#PIN
Kumron Boonget
Kumron Boonget

Operations professional at a container and ISO tank depot in Thailand. He builds the systems his team uses every day with Google Sheets, Apps Script and AppSheet, from search pages to repair tracking and automatic alerts, and shares how to build them in plain language for non-programmers.

Comments

No comments yet. Be the first to share your thoughts or ask a question.

Leave a comment
Comments are reviewed before they appear.

Read next