<pre><code>&lt;input type="hidden" name="foo" value="{{ 'bar'|hash }}"&gt;
</code></pre>

<p>and then in your controller:</p>

<pre><code>if (($foo = craft()-&gt;request-&gt;getPost('foo')) !== null)
{
    $foo = craft()-&gt;security-&gt;validateData($foo);
}
</code></pre>

<p>at which point $foo will either be <code>null</code> (not present), <code>false</code> (present but tampered with), or a string (present and valid)</p>

CC BY-SA 3.0
2016-03-24T05:31:48.893Z
2016-03-24T07:30:32.707Z
2016-03-24T07:30:32.707Z
Luke Holder
<p>I've used <a href="http://hashids.org/" rel="nofollow">hashids</a> successfully before, then create a small plugin helper with a twig filter that transforms the id into a hash that also decrypts it. you can include composer to craft plugins by just updating your composer file and adding hashids to it.</p>

CC BY-SA 3.0
2016-03-24T14:00:12.697Z
2016-03-24T14:00:12.697Z
Xpertbot
<p>I have a front-end form that posts through the ID of a particular element/entry to a back-end controller. Is there any way to encrypt/hash that ID on the front-end, so the plain ID number is not visible, and then decrypt that ID in the back-end controller?</p>

<form><security><hash><id>
Encrypt ID on front-end and decrypt on back-end
# Encrypt ID on front-end and decrypt on back-end

(Asked by: username_0 on 2016-03-24)

I have a front-end form that posts through the ID of a particular element/entry to a back-end controller. Is there any way to encrypt/hash that ID on the front-end, so the plain ID number is not visible, and then decrypt that ID in the back-end controller?

**Tags:** form, security, hash, id


---

## 2 answers

### Answer by username_1 on 2016-03-24. Score: 3

and then in your controller:
if (($foo = craft()->request->getPost('foo')) !== null)
{
    $foo = craft()->security->validateData($foo);
}

at which point $foo will either be null (not present), false (present but tampered with), or a string (present and valid)


---

### Answer by username_2 on 2016-03-24. Score: 1

I've used [hashids](http://hashids.org/) successfully before, then create a small plugin helper with a twig filter that transforms the id into a hash that also decrypts it. you can include composer to craft plugins by just updating your composer file and adding hashids to it.


---

