Migrating an Existing Website from SQL Membership to ASP.

Source: Internet
Author: User

Migrating an Existing Website from SQL Membership to ASP.

 Public classUser:identityuser { PublicUser () {createdate=DateTime.Now; IsApproved=false; Lastlogindate=DateTime.Now; Lastactivitydate=DateTime.Now; Lastpasswordchangeddate=DateTime.Now; Lastlockoutdate= DateTime.Parse ("1/1/1754"); Failedpasswordanswerattemptwindowstart= DateTime.Parse ("1/1/1754"); Failedpasswordattemptwindowstart= DateTime.Parse ("1/1/1754"); }         PublicSystem.Guid ApplicationID {Get;Set; }  Public stringMobilealias {Get;Set; }  Public BOOLisanonymous {Get;Set; }  PublicSystem.DateTime Lastactivitydate {Get;Set; }  Public stringMobilepin {Get;Set; }  Public stringLoweredemail {Get;Set; }  Public stringLoweredusername {Get;Set; }  Public stringpasswordquestion {Get;Set; }  Public stringpasswordanswer {Get;Set; }  Public BOOLisapproved {Get;Set; }  Public BOOLIslockedout {Get;Set; }  PublicSystem.DateTime CreateDate {Get;Set; }  PublicSystem.DateTime Lastlogindate {Get;Set; }  PublicSystem.DateTime Lastpasswordchangeddate {Get;Set; }  PublicSystem.DateTime Lastlockoutdate {Get;Set; }  Public intFailedpasswordattemptcount {Get;Set; }  PublicSystem.DateTime Failedpasswordattemptwindowstart {Get;Set; }  Public intFailedpasswordanswerattemptcount {Get;Set; }  PublicSystem.DateTime Failedpasswordanswerattemptwindowstart {Get;Set; }  Public stringComment {Get;Set; } }
       Public classSqlpasswordhasher:passwordhasher { Public Override stringHashpassword (stringpassword) {            return Base.        Hashpassword (password); } Public OverridePasswordverificationresult Verifyhashedpassword (stringHashedpassword,stringProvidedpassword) {            string[] passwordproperties = Hashedpassword.split ('|'); if(Passwordproperties.length! =3)            {                return Base.            Verifyhashedpassword (Hashedpassword, Providedpassword); }            Else            {                stringPasswordHash = passwordproperties[0]; intPasswordformat =1; stringSalt = passwordproperties[2]; if(String.Equals (Encryptpassword (Providedpassword, passwordformat, salt), PasswordHash, Stringcomparison.currentcultureignorecase)) {returnpasswordverificationresult.successrehashneeded; }                Else                {                    returnpasswordverificationresult.failed; }            }        }//This was copied from the existing SQL providers and was provided only for Back-compat.        Private stringEncryptpassword (stringPassintPasswordformat,stringSalt) {            if(Passwordformat = =0)//Membershippasswordformat.clear                returnPass; byte[] BIn =Encoding.Unicode.GetBytes (pass); byte[] Bsalt =convert.frombase64string (salt); byte[] BRet =NULL; if(Passwordformat = =1)            { //membershippasswordformat.hashedHashAlgorithm HM = Hashalgorithm.create ("SHA1"); if(HM isKeyedHashAlgorithm) {KeyedHashAlgorithm Kha=(KeyedHashAlgorithm) HM; if(Kha. Key.length = =bsalt.length) {kha. Key=Bsalt; }                    Else if(Kha. Key.length <bsalt.length) {byte[] Bkey =New byte[Kha.                        Key.length]; Buffer.blockcopy (Bsalt,0, Bkey,0, bkey.length); Kha. Key=Bkey; }                    Else                    {                        byte[] Bkey =New byte[Kha.                        Key.length];  for(intITER =0; ITER <bkey.length;) {                            intLen = Math.min (bsalt.length, Bkey.length-ITER); Buffer.blockcopy (Bsalt,0, Bkey, ITER, Len); ITER+=Len; } kha. Key=Bkey; } BRet=Kha.computehash (bIn); }                Else                {                    byte[] Ball =New byte[Bsalt.length +Bin.length]; Buffer.blockcopy (Bsalt,0, Ball,0, bsalt.length); Buffer.blockcopy (BIn,0, Ball, Bsalt.length, bin.length); BRet=Hm.computehash (ball); }            }            returnconvert.tobase64string (BRet); }
 Public Usermanager ()             Base (new userstore<user> (new  Applicationdbcontext ()))        {            thisnew  sqlpasswordhasher ();}
PrivateGuid Getapplicationid () {using(SqlConnection connection =NewSqlConnection (configurationmanager.connectionstrings["ApplicationServices"]. ConnectionString)) {stringQueryString ="SELECT ApplicationID from aspnet_applications WHERE applicationname = '/'";//Set application name as in databaseSqlCommand Command=NewSqlCommand (queryString, connection); Command.                Connection.Open (); varReader =command.                ExecuteReader ();  while(reader. Read ()) {returnReader. GetGuid (0); }                returnGuid.NewGuid (); }        }
var currentapplicationid =new User () {UserName = Username.text,applicationid =currentapplicationid, ...};

Migrating an Existing Website from SQL Membership to ASP.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.