membership

Reading membership section from web.config

半世苍凉 提交于 2019-12-01 03:07:31
问题 I have created a custom MembershipProvider class, so far so good, however, I am not sure how to read the configuration settings from the web.config file. I tried to search from Google and Stackoverflow, seems like someone also experiencing my problem and asked, but no answer has been given. It should be a simple thing, but I am very new in web development, so reading settings from web.config seems away too technical to me. Here is my settings: <membership defaultProvider=

ASP.Net Membership saves changed password as plain text even with Hashed passwordFormat set

我们两清 提交于 2019-11-30 16:22:10
I'm using the ASP.Net SqlMembershipProvider to manage my users. Here is my config: <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15"> <providers> <clear /> <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SiteDatabase" applicationName="WPR" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed"

ASP.NET Membership C# - How to compare existing password/hash

眉间皱痕 提交于 2019-11-30 14:26:17
问题 I have been on this problem for a while. I need to compare a paasword that the user enters to a password that is in the membership DB. The password is hashed and has a salt. Because of the lack of documentation I do not know if the salt is append to the password and then hashed how how it is created. I am unable to get this to match. The hash returned from the function never matches the hash in the DB and I know for fact it is the same password. Microsoft seems to hash the password in a

ASP.Net Store User Data in Auth Cookie

二次信任 提交于 2019-11-30 06:26:16
问题 I want to store some data like the user nickname and user ID (table primary key) in the user data section of the auth cookie. The reason I'm doing this is to retain this data when the browser is closed, without having the user relogin. Edit : Whoops! Realized I'd not explained myself well. I am not trying to reauthenticate a user based on their cookie. The user is already authenticated by ASP.Net's membership system - this part is fine. My problem is that if I want to show the user's nickname

Membership Generate Password alphanumeric only password?

落爺英雄遲暮 提交于 2019-11-30 04:15:16
How can I use Membership.GeneratePassword to return a password that ONLY contains alpha or numeric characters? The default method will only guarantee a minimum and not a maximum number of non alphanumeric passwords. string newPassword = Membership.GeneratePassword(15, 0); newPassword = Regex.Replace(newPassword, @"[^a-zA-Z0-9]", m => "9" ); This regular expression will replace all non alphanumeric characters with the numeric character 9. I realised that there may be ways of doing this. The GUID method is great, except it doesn't mix UPPER and lower case alphabets. In my case it produced lower

ASP.Net logout code block

谁说胖子不能爱 提交于 2019-11-29 21:11:50
问题 I need a good logout code block for asp.net. Currently after you logout you can hit the back button and continue using the site. 回答1: You need to make sure that the session is abandoned and call the FormsAuthentication.SignOut() method as shown below: private void Logout() { Session.Abandon(); FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage(); } 回答2: Assuming you're using Forms Authentication, you would just do: System.Web.FormsAuthentication.SignOut(); Without more

programmatic login with .net membership provider

随声附和 提交于 2019-11-29 19:38:45
问题 I'm trying to unit test a piece of code that needs a currently logged in user in the test. Using the .Net 2.0 Membership Provider, how can I programmatically log in as a user for this test? 回答1: if(Membership.ValidateUser("user1",P@ssw0rd)) { FormsAuthentication.SetAuthCookie("user1",true); } 回答2: I've found it most convenient to create a disposable class that handles setting and resetting Thread.CurrentPrincipal. public class TemporaryPrincipal : IDisposable { private readonly IPrincipal

Godaddy ASP.NET membership database woes

痞子三分冷 提交于 2019-11-29 11:53:11
I purchased a Windows shared hosting account on godaddy that came with 2 MSSQL databases. I setup one to hold my site data and the other installed aspnet membership schema to store site members. The site works perfectly even displaying data from the 1st database. However when I try to login or register I get this nasty error Exception Details: System.Configuration.Provider.ProviderException: The SSE Provider did not find the database file specified in the connection string. At the configured trust level (below High trust level), the SSE provider can not automatically create the database file.

asp.net membership - how to determine programmatically is user is in role

百般思念 提交于 2019-11-29 09:36:08
What is the code for determining if a user is in a role? I have set up all the users through the ASP.NET Configuration Security tab but now want to put logic around some key areas so only people in certain roles can see and access these areas. if (User.IsInRole("rolename")) { // my action } Easy~ HttpContext.Current.User.IsInRole("roleName") Matthew Jones Check out the Roles class, specifically IsUserInRole, GetUsersInRole, AddUserToRole, etc. I use these all the time. thanks to "Chris Van Opstal". i solved my problem like this way, public ActionResult Index() { if (User.IsInRole("Supervisor")

Login fails after upgrade to ASP.net 4.0 from 3.5

随声附和 提交于 2019-11-29 07:09:40
I cannot log in using any of the membership accounts using .net 4.0 version of the app. It fails like it's the wrong password, and FailedPasswordAttemptCount is incremented in my_aspnet_membership table. (I am using membership with mysql membership provider.) I can create new users. They appear in the database. But I cannot log in using the new user credentials (yes, IsApproved is 1). One clue is that the hashed passwords in the database is longer for the users created using the asp.net 4.0 version, e.g 3lwRden4e4Cm+cWVY/spa8oC3XGiKyQ2UWs5fxQ5l7g=, and the old .net 3.5 ones are all like