+ 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?

17th Mar 2018, 3:22 PM
Curt Griffin
Curt Griffin - avatar
10 Answers
+ 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?
17th Mar 2018, 3:36 PM
Burey
Burey - avatar
+ 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
17th Mar 2018, 5:47 PM
Burey
Burey - avatar
+ 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.
17th Mar 2018, 3:31 PM
Aaron Stone
Aaron Stone - avatar
+ 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.
17th Mar 2018, 7:35 PM
Mike Choy
Mike Choy - avatar
+ 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
17th Mar 2018, 6:39 PM
Mike Choy
Mike Choy - avatar
+ 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?
17th Mar 2018, 4:57 PM
Curt Griffin
Curt Griffin - avatar
+ 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.
17th Mar 2018, 7:12 PM
Curt Griffin
Curt Griffin - avatar
+ 1
Awesome. I'll look into it. Thanks!
17th Mar 2018, 7:51 PM
Curt Griffin
Curt Griffin - avatar
0
Like a list maybe?
17th Mar 2018, 3:34 PM
Curt Griffin
Curt Griffin - avatar