If you don't want to use any Server languages. You can just use window.localStorage.setItem('username', theUsernameFromOtherThing);
as suggested by @Paul S
However if you want also want to use a server language(such as PHP) I recommend a cookie, but beware of storing secure data in a cookie, since anyone sniffing can just grab it.
Also if you are sending you username and password to a url on another server, you better check that your domain, and the domain you are posting to, starts with https.
I highly recommend Sitepoint for their very simplified guides. http://www.sitepoint.com/how-to-deal-with-cookies-in-javascript/ if you wan't to learn basic web development.