Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Extensions / ClientServices / ClientFormsIdentity.cs / 1305376 / ClientFormsIdentity.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.ClientServices { using System; using System.Net; using System.Security.Principal; using System.Runtime.InteropServices; using System.Security; using System.Web.Security; using System.Diagnostics.CodeAnalysis; public class ClientFormsIdentity : IIdentity, IDisposable { public string Name { get { return _Name; }} public bool IsAuthenticated { get { return _IsAuthenticated; }} public string AuthenticationType { get { return _AuthenticationType; } } public CookieContainer AuthenticationCookies { get { return _AuthenticationCookies; } } public MembershipProvider Provider { get { return _Provider; } } public ClientFormsIdentity(string name, string password, MembershipProvider provider, string authenticationType, bool isAuthenticated, CookieContainer authenticationCookies) { _Name = name; _AuthenticationType = authenticationType; _IsAuthenticated = isAuthenticated; _AuthenticationCookies = authenticationCookies; _Password = GetSecureStringFromString(password); _Provider = provider; } public void RevalidateUser() { if (_Disposed) { throw new ObjectDisposedException(this.GetType().FullName); } _Provider.ValidateUser(_Name, GetStringFromSecureString(_Password)); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { if (_Password != null) { _Password.Dispose(); } } _Disposed = true; } private string _Name; private bool _IsAuthenticated; private string _AuthenticationType; private CookieContainer _AuthenticationCookies; private SecureString _Password; private MembershipProvider _Provider; private bool _Disposed; private static SecureString GetSecureStringFromString(string password) { char[] passwordChars = password.ToCharArray(); SecureString ss = new SecureString(); for (int iter = 0; iter < passwordChars.Length; iter++) ss.AppendChar(passwordChars[iter]); ss.MakeReadOnly(); return ss; } [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification="Reviewed and approved by feature crew")] [SecuritySafeCritical] private static string GetStringFromSecureString(SecureString securePass) { IntPtr bstr = IntPtr.Zero; try { bstr = Marshal.SecureStringToBSTR(securePass); return Marshal.PtrToStringBSTR(bstr); } finally { if (bstr != IntPtr.Zero) Marshal.FreeBSTR(bstr); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.ClientServices { using System; using System.Net; using System.Security.Principal; using System.Runtime.InteropServices; using System.Security; using System.Web.Security; using System.Diagnostics.CodeAnalysis; public class ClientFormsIdentity : IIdentity, IDisposable { public string Name { get { return _Name; }} public bool IsAuthenticated { get { return _IsAuthenticated; }} public string AuthenticationType { get { return _AuthenticationType; } } public CookieContainer AuthenticationCookies { get { return _AuthenticationCookies; } } public MembershipProvider Provider { get { return _Provider; } } public ClientFormsIdentity(string name, string password, MembershipProvider provider, string authenticationType, bool isAuthenticated, CookieContainer authenticationCookies) { _Name = name; _AuthenticationType = authenticationType; _IsAuthenticated = isAuthenticated; _AuthenticationCookies = authenticationCookies; _Password = GetSecureStringFromString(password); _Provider = provider; } public void RevalidateUser() { if (_Disposed) { throw new ObjectDisposedException(this.GetType().FullName); } _Provider.ValidateUser(_Name, GetStringFromSecureString(_Password)); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { if (_Password != null) { _Password.Dispose(); } } _Disposed = true; } private string _Name; private bool _IsAuthenticated; private string _AuthenticationType; private CookieContainer _AuthenticationCookies; private SecureString _Password; private MembershipProvider _Provider; private bool _Disposed; private static SecureString GetSecureStringFromString(string password) { char[] passwordChars = password.ToCharArray(); SecureString ss = new SecureString(); for (int iter = 0; iter < passwordChars.Length; iter++) ss.AppendChar(passwordChars[iter]); ss.MakeReadOnly(); return ss; } [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification="Reviewed and approved by feature crew")] [SecuritySafeCritical] private static string GetStringFromSecureString(SecureString securePass) { IntPtr bstr = IntPtr.Zero; try { bstr = Marshal.SecureStringToBSTR(securePass); return Marshal.PtrToStringBSTR(bstr); } finally { if (bstr != IntPtr.Zero) Marshal.FreeBSTR(bstr); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EdgeProfileValidation.cs
- OpenFileDialog.cs
- ClientCultureInfo.cs
- ScriptManager.cs
- FilterQuery.cs
- TableLayoutRowStyleCollection.cs
- PropertyEmitterBase.cs
- ResourceDictionaryCollection.cs
- ParsedRoute.cs
- FixedPageAutomationPeer.cs
- InstanceDataCollection.cs
- MaskedTextBoxTextEditor.cs
- WriterOutput.cs
- TypeFieldSchema.cs
- ImageKeyConverter.cs
- RuntimeConfigLKG.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- BamlMapTable.cs
- DataObject.cs
- TemplateControlParser.cs
- PeerNameRecord.cs
- StorageModelBuildProvider.cs
- FixedDSBuilder.cs
- DataGridTablesFactory.cs
- WaitHandleCannotBeOpenedException.cs
- CurrentChangingEventArgs.cs
- DateTimeConverter.cs
- CodeArgumentReferenceExpression.cs
- SplineQuaternionKeyFrame.cs
- PackageDigitalSignatureManager.cs
- DuplicateMessageDetector.cs
- _SecureChannel.cs
- DNS.cs
- PermissionRequestEvidence.cs
- ErrorsHelper.cs
- ThrowHelper.cs
- EntityException.cs
- TextWriter.cs
- PropVariant.cs
- WebPart.cs
- MetadataItemEmitter.cs
- AttributeCollection.cs
- MoveSizeWinEventHandler.cs
- Knowncolors.cs
- TargetConverter.cs
- CustomSignedXml.cs
- _Win32.cs
- ServiceDescriptionSerializer.cs
- FormatterConverter.cs
- XmlSchemaSimpleContentRestriction.cs
- XmlSchemaFacet.cs
- FileIOPermission.cs
- ToolStripItemDesigner.cs
- DeferredReference.cs
- ObjectDataSourceMethodEventArgs.cs
- AdornedElementPlaceholder.cs
- PowerStatus.cs
- sqlmetadatafactory.cs
- arclist.cs
- AppLevelCompilationSectionCache.cs
- DataViewSettingCollection.cs
- RuleSettingsCollection.cs
- ParameterModifier.cs
- ReflectTypeDescriptionProvider.cs
- DataSourceControl.cs
- SemanticAnalyzer.cs
- CodeDOMUtility.cs
- DataContractAttribute.cs
- HttpCacheVaryByContentEncodings.cs
- securitymgrsite.cs
- InvalidCastException.cs
- BinaryMethodMessage.cs
- TextServicesHost.cs
- XsltCompileContext.cs
- ContextProperty.cs
- FreezableCollection.cs
- SqlMethodAttribute.cs
- MessageHeaders.cs
- EntryWrittenEventArgs.cs
- Base64Stream.cs
- LineServices.cs
- PointAnimationClockResource.cs
- CriticalFinalizerObject.cs
- ActivityTypeResolver.xaml.cs
- InternalBufferManager.cs
- DesignTimeTemplateParser.cs
- AlignmentXValidation.cs
- PointUtil.cs
- DocumentViewerBase.cs
- Timer.cs
- BaseParser.cs
- CompositeKey.cs
- TypeRefElement.cs
- WebPartConnectionsCancelEventArgs.cs
- BamlResourceContent.cs
- CompilerParameters.cs
- AddingNewEventArgs.cs
- SatelliteContractVersionAttribute.cs
- AppDomainFactory.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs