+ 1
How do I create Key:Value pairs for username and password?
Building a website and I want to create an array holding usernames and passwords indexed together as key:value pairs but I don't know how to do this in JS. Is this possible? If not, what can I do? If it can be done, how do I access them afterwards? Or check for them with a conditional?
10 odpowiedzi
+ 10
using an object where the key is the username is possible, or an array of objects:
[{username: "some name", password: "some password"}, .....]
but i am having hard time to understand what exactly you are aiming to do
authentication system on the server? on the client?
can you give more background to what you are trying to achieve?
+ 6
authontication is always done on the backend (you do not want to send the username:password list to the client for authentication and allow everyone to see it, right? )
it is also better to generate a hash (basically a long long string generated from the password and usually a secret key held on the server) instead of a password for security reasons.
but if you are only beginning then using passwords is no issue for practice purposes
you can practice on your computer and build it with a backend (there are plenty of tutorials for that)
OR
do it on SL playground to get the hang of it, simulating a server, perhaps with promises or timeout
+ 5
some tutorials on authentication (node.js as backend)
and other articles that might be relevant
https://medium.com/of-all-things-tech-progress/starting-with-authentication-a-tutorial-with-node-js-and-mongodb-25d524ca0359
https://scotch.io/amp/tutorials/authenticate-a-node-js-api-with-json-web-tokens
https://medium.freecodecamp.org/my-journey-to-becoming-a-web-developer-from-scratch-without-a-cs-degree-2-years-later-and-what-i-4a7fd2ff5503
https://medium.com/developers-writing/8-steps-to-building-an-app-from-scratch-a1e21c67756d
https://ruslanspivak.com/lsbaws-part1/
+ 3
I don't know much about JavaScript, however I guess it's gonna be tough using Arrays. You are gonna need a more easily accessible and more compact structure.
+ 3
Not sure if you are looking at encryption on the client or server. Not something you should write your self. As @Bury says use Node.js server side, plenty of libraries available on npm. If it's a production website why not just use one of the OOB solutions like Wix. That way you won't have to worry about certificates, domain names, and PKI.
+ 2
Hi Curt
Here is a simple example of an array of user objects and how to use
https://code.sololearn.com/Wm9Ns6xATsIg/#js
Also here is simple example how you can traverse an array either with for loops or using recursion
https://code.sololearn.com/WtP7m1q66k33/#html
see the JS tabs
+ 1
Yes, authentication system for login. I'm new to this and don't really know if it's client or server side. I'm building a site in this app to practice and learn. So, I guess, client? Since it isn't a live site?
+ 1
I was wondering how to hide the list. I have heard of hash/key concept but I just haven't gotten to encryption or backend yet. Thanks for the info! It always helps to have a good starting point.
+ 1
Awesome. I'll look into it. Thanks!
0
Like a list maybe?