. NET generates a unique 6-bit invitation code based on the user ID that can be reversed.

Source: Internet
Author: User
Today to do the invitation code this function, but I do not bother to modify the database table structure, and then read a lot of blogs on the internet, and then a blog above the PHP read a way to write, and then according to my understanding to rewrite into. Net. Words do not say more directly paste code.
 static void Main (string[] args) {int num = 10086;
            Console.WriteLine (Createcode (num));
            Console.WriteLine (Decode (Createcode (num)));
        Console.readkey ();
            public static string Createcode (int Id) {String code = "";
            String source_string= "2yu9ip6asdfg8qwerthj7klzx4cv5b3onm1";//Custom 35 int mod = 0;
            StringBuilder sb = new StringBuilder ();
                while (ID > 0) {mod = id% 35;
                Id = (id-mod)/35; Code = source_string.

            ToCharArray () [mod]+ code; Return code. PadRight (6, ' 0 ');/less than six-bit complement 0} public static int decode (string code) {code =new string (f Rom s in code where s!= ' 0 ' select s).
            ToArray ());
            int num = 0;
            String source_string = "2YU9IP6ASDFG8QWERTHJ7KLZX4CV5B3ONM1"; for (int i = 0; i < code. ToCharArray (). Length; i++) {for (int j = 0; J < source_string. ToCharArray (). Length; J + +) {if (code. ToCharArray () [i]== source_string. ToCharArray () [j]) {num = J*convert.toint32 (Math.pow, code. ToCharArray ().
                    LENGTH-I-1));
        }} return num; }

The advantage of this writing is that others do not know the order of your system, so it is difficult to reverse your user ID from the invitation code.

I'm just a rookie on the way to programming, and you are welcome to criticize me.

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.