0

Someone change variable value of their data in my website.
Next step this variable value pass to server from api call.

It change value in chrome browser by following steps.
Open chrome -> Inspect Element -> Source -> Scope

I was put all validation like, user can not open inspect element from using of any shortcut keys.

Following is sample code and my situation enter image description here

How can prevent user for modify value of variables?

Bhaumik Surani
  • 1,730
  • 3
  • 19
  • 40
  • https://stackoverflow.com/questions/54704413/prevent-inspect-element-in-text-field. Why not if we disable the user for inspecting the html document by any of the means like by direct opening or shortcut key. – Shamoon97 Jul 02 '22 at 07:44
  • currently i use javascript-obfuscator. using of this prevent user for debugging https://www.npmjs.com/package/javascript-obfuscator – Bhaumik Surani Jul 15 '22 at 04:58

1 Answers1

1

You've should use const keyword. It similar to let keyword but not the same.

By declaring with const keyword it's value can only be Read by user and cannot be modified. It does not allow to change it's value to change through reassignment and it cannot be redeclared.

If you declare data types with const keyword object and arrays, it's properties or items can be updated or removed.

if you try to reassign the constant variable it will throw an error.

let num1 = 1;
const num2 = 1;

console.log(num1);
num1 = 2;
console.log(num1);

console.log(num2);
num2 = 2;
console.log(num2);
Extraterrestrial
  • 600
  • 1
  • 6
  • 19
  • It's not working for me. Form Inspect Element value was changes – Bhaumik Surani Jul 02 '22 at 08:13
  • If you want to secure your code, you just can't do that. But as an alternative you can print a bold message in console or body which display - _warning to user_ . But using `const` keyword has certain protections – Extraterrestrial Jul 02 '22 at 08:20