Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6992397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:37:45+00:00 2026-05-27T19:37:45+00:00

Possible Duplicate: How to use Basic Auth and Jquery and Ajax I want to

  • 0

Possible Duplicate:
How to use Basic Auth and Jquery and Ajax

I want to use basic authentication via AJAX to a REST service. The authentication header is not my problem. My problem is how do I go about storing and retrieving the credentials that will be used in the basic authentication.

Should I be storing the username and password in a cookie when they first log in? I want the user to be able to login to the website. And once they are logged in, their web browser will download the page contents via AJAX with basic authentication from a REST service that contains their data.

I think there must be some standard way to do this. But I am having a hard time figuring out what it is.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:37:45+00:00Added an answer on May 27, 2026 at 7:37 pm

    I marked the question as a dupe after I figured out exactly what was being asked.

    Here’s an answer about how you’d roll your own Auth system, which is originally what I thought your question was about 🙂


    If your site is visible on the Internet, HTTP Basic Auth alone will not secure your content.

    Sending the username and password to the server

    You shouldn’t store the username and password anywhere but inside your DB. The password should never be stored in plain text. It should be hashed, using a Salt.

    When you authenticate, hash the password with the same Salt, and verify that the resulting hashes are the same.

    You could also consider a pre-hash of the password (in addition to the server-side hash) so the plain-text password is never sent over the wire.

    Session cookie instead of username/password with each request

    Authenticate with the username and password only once, and return a session cookie to the user.

    This cookie should be used to look up which user owns the session, and when they authenticated (so the session can expire). If they’ve got a valid cookie that matches up to an unexpired session, you can consider them authenticated.

    Security issues

    The remaining problems with this scheme are that it is still going to be prone to a replay attack or a man-in-the-middle attack.

    You could mitigate some of this by only allowing authenticated sessions to access your site through SSL.

    Another thing that could help (though not completely solve the problem) is store the IP the auth request came from in the session data, and make sure it is the same IP with each request.

    If you can, I’d suggest you reuse an existing authentication system rather than rolling your own. It is a little complicated (and prone to problems), and other people have already thought through the details. I’m sure there are details I’m missing, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Why not use tables for layout in HTML? I know everyone is
Possible Duplicate: Why not use Double or Float to represent currency? I'm writing a
Possible Duplicate: Workaround for basic syntax not being parsed Why don't PHP attributes allow
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the
Possible Duplicate: Why use document.write? Considering the negative effects of document.write(), why are most
Possible Duplicate: When to use “strictfp” keyword in java? What is the use of
Possible Duplicate: When to Use Static Classes in C# Questions in the title..........i would
Possible Duplicate: Internationalization in SSRS We use SQL Server Reporting Services for our web
Possible Duplicate: How can I use a carriage return in a HTML tooltip? I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.