0

I have a JavaScript file which I run locally which connects to an API. Currently I store the login details in a config file, but I don't want to do this.

Instead I want to present the user with a login form (with no backend, only JS) and have those credentials somehow stored with a reasonable level of security and used as the credentials for the API access, instead of using hardcoded ones.

Is this even possible in JavaScript?

chazsolo
  • 7,873
  • 1
  • 20
  • 44
Jimmy
  • 12,087
  • 28
  • 102
  • 192
  • 1
    Well, Jimmy, that's what databases are for. – Phiter Aug 30 '18 at 19:07
  • 1
    You can store those details in localStorage or sessionStorage using javascript if you don't want to use a db. Better to do a hash and store in db, though. – Iskandar Reza Aug 30 '18 at 19:08
  • 2
    So, the API *is* the backend that takes login details? Put an `` in your page and have the user enter the API credentials. – Bergi Aug 30 '18 at 19:08
  • You can't store them safely anywhere without a backend. – Phiter Aug 30 '18 at 19:08
  • @Bergi That's what I want to go, but I don't want to use a server side language or store it in a database? – Jimmy Aug 30 '18 at 19:27
  • 2
    if you're willing to sacrifice "a reasonable level of security", you can definitely just do what @I.R.R. suggests and store the credentials in localstorage, but if you want to afford your users any kind of protection you will need a database – Hamms Aug 30 '18 at 19:37
  • @Jimmy Ask the user for the credentials every time you call the API. Or store them in a local variable while the page is loaded. If you want to preserve it across page loads, see the duplicate for various options. – Bergi Aug 30 '18 at 20:29

0 Answers0