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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:40:28+00:00 2026-06-10T16:40:28+00:00

I am creating SQLAlchemy class that represents user credentials. I want to have field

  • 0

I am creating SQLAlchemy class that represents user credentials.

I want to have field password that stores hashed value of password. Therefore I would like to override its behavior the following way:

  1. When assigned credentials.password = value it actually stores hash of the value

  2. When comparing credentials.password == value it actually compares with hash of the value

I have read the following part of SQLAlchemy documentation http://docs.sqlalchemy.org/en/rel_0_7/orm/mapper_config.html#using-descriptors-and-hybrids

And I think I do understand how to solve the issue number 1.

I am however unsure, how to do second point. Is there a way to do it the safe way (without breaking SQLAlchemy)?

Here is the example model:

class Credentials(Base):
    __tablename__ = 'credentials'

    id = Column(Integer, primary_key=True)

    _password = Column('password', String)

    @hybrid_property
    def password(self):
        return self._password

    @password.setter(self):
        self._password = hash(self._password)
  • 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-06-10T16:40:30+00:00Added an answer on June 10, 2026 at 4:40 pm

    For comparing, since you can’t un-hash the password, you would need to create a custom type for the Column class, that over-rides the eq operator:

    class MyPasswordType(String):
        class comparator_factory(String.Comparator):
            def __eq__(self, other):
                return self.operate(operators.eq, hash(other))
    

    Have a look at: http://docs.sqlalchemy.org/en/latest/core/types.html#types-operators

    And http://docs.sqlalchemy.org/en/latest/core/types.html#sqlalchemy.types.TypeEngine.comparator_factory

    To set you just need to pass in the value:

    @password.setter
    def password(self, value):
        self._password = hash(value)    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating an installer for possible remote systems so that if they do not have
I am creating table with sqlalchemy. user = Table('users', Metadata, Column('datecreated', TIMESTAMP, server_default=text('CURRENT_TIMESTAMP')), Column('datemodified',
I have very simple code that cause my MySQL db to hang: import sqlalchemy
I have a SQL query that I execute like this with an SQLAlchemy engine:
Creating a class at runtime is done as follows: klass = Class.new superclass, &block
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a google map with store locations within 50 miles of user entered address.
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Error creating bean with name 'sessionFactory' defined in class path resource [ApplicationContext.xml]: Invocation of
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking

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.