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 4021044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:18:11+00:00 2026-05-20T10:18:11+00:00

As user logged in, he had provided his name and raw password which was

  • 0

As user logged in, he had provided his name and raw password which was hashed and compared with db’s value.


def login(request):
    username = request.POST['username']
    password = request.POST['password']
    user = auth.authenticate(username=username, password=password)
    if user is not None and user.is_active:
        # user is active
        auth.login(request, user)
        # relink to right page
        return HttpResponseRedirect("/account/loggedin/")
    else:
        # error page
        return HttpResponseRedirect("/account/invalid/")

or I could just use:


@login_required
def index(request):
    if request.user.is_authenticated():
        return render_to_response('polls/index.html', {'sessionDic' : request.session})
    else:
        #some stuff

The problem is: once user logged in, the following requests comprises only cookies which are checked and user have no need to put his credentials again.


But, I need to have raw user’s password in View in every method to log in to linux user and execute some linux program as this user. For exmaple the su program is used to switch the ritgh linux user:


def ssh_command (user, password, command):
    child = pexpect.spawn('su -l %s -c \'%s\'' % (user, command))
    i = child.expect([pexpect.TIMEOUT, pexpect.EOF, 'Password: '])
    if i == 0: # Timeout
        print 'ERROR!'
        print 'su can\'t be executed:'
        print child.before, child.after
        return None
    if i == 1: # EOF
        print 'ERROR'
        print 'EOF error'
        print child.before, child.after
        return None
    child.sendline(password)
    return child

def main ():
    user = 'test'
    password = 'test'
    child = ssh_command (user, password, 'curl habrahabr.ru | wc -c')
    child.expect(pexpect.EOF)
    print child.before
    print child.after
    print child.match

How can I store raw user’s password and substitute it to required functions?

  • 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-20T10:18:12+00:00Added an answer on May 20, 2026 at 10:18 am

    You could store it in the session data from the login view function. At least then it would die with the session. The other option, stashing it in a database field, would be horrendous if some hacker got DB access. At least if a hacker gets DB access with passwords in sessions they’d only get the plain text passwords of current sessions. Make sure you timeout sessions appropriately, or encourage your users to logout and remove session data on logout.

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

Sidebar

Related Questions

doing a simple login for my website, which will hopefully keep the user logged
I have the following class which handles my user logged in / logged out
I've got some nifty code that on user login, finds any other user logged
Suppose that I had a logged in user through the Facebook PHP SDK, and
If user logged in then it's show status is ON because of i run
Should I be writing assertTrue(User logged in, user.isLoggedIn()); or assertTrue(User is not logged in,
I have a JSF session scope bean and I'm keeping current user(logged in) information
I have a blog post page with comments. Any user (logged in or not)
Scenario: User X1 logged in. He can not be logged again. up to previous
I would like to allow the logged user to edit MediaWiki/Common.css without adding them

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.