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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:43:31+00:00 2026-06-11T03:43:31+00:00

This is what my user model looks like: namespace Api.Models { public class User

  • 0

This is what my user model looks like:

namespace Api.Models
{
    public class User
    {

        [BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
        [BsonRequired]
        public string Id { get; set; }

        [Required(ErrorMessage = "Username is required.")]
        [StringLength(20, MinimumLength=3, ErrorMessage="Username must be between 3 and 20 characters.")]
        [BsonRequired]
        public string Username { get; set; }

        [Required(ErrorMessage="Email is required.")]
        [EmailAddress(ErrorMessage="Valid email required.")]
        [BsonRequired]
        public string Email { get; set; }

        [Required(ErrorMessage = "Password is required.")]
        [StringLength(50, MinimumLength=8, ErrorMessage="Password must be between 8 and 50 characters.")]
        [BsonRequired]
        public string Password { get; set; }

        [BsonRequired]
        public string Salt { get; set; }

    }
}

I want to write, and require, all of the properties into the MongoDB Database. What I don’t want to do, is expose the Password and Salt properties when I send this through the request.

Is there any sort of data attribute that I can set that will write it, but not expose it when displayed to any API user?

  • 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-11T03:43:32+00:00Added an answer on June 11, 2026 at 3:43 am

    The correct approach is to use view models. Don’t pass your domain entities to the views. Design view models that meet the specific requirements of your views. So for example design a view model that doesn’t have the Password and Salt properties because that’s what this view needs. Then in order to ease the mapping between your domain models and view models you could use AutoMapper.

    If you don’t want to follow good practices with view models you still have the possibility to clutter your POST actions with the Bind attribute and decide which properties you want to be included/excluded from model binding. For example:

    [HttpPost]
    public ActionResult SomeAction([Bind(Exclude="Password,Salt")]User user)
    {
        // at this stage the Password and Salt properties will always be null =>
        // they will never be bound from the request even if the user attempts to 
        // forge an HTTP request and include them
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I am working with a Django model that looks like this: class Subscription(models.Model): user
This is how my data model for USER looks like public class User {
I have a model that looks like this: public class UserAdminEditViewModel { public User
My Model looks like like this public class User { public int ID {
My model is like this class Foo(models.Model): user = models.ForeignKey(User) class Meta: abstract =
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I've got a model that looks something like this class SecretKey(Model): user = ForeignKey('User',
This is my model class UserAward(models.Model): user = models.ForeignKey(User, related_name='awards') award = models.CharField(max_length=255) week
I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end

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.