Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am developing simple registration form in that form i kept mobile number. After user registerd the form completely a unique code should go to his mobile. when he want's to login for the first time he should validate the code that is in mobile. I kept one page for mobile code validation. I want to know how the code is randomly generated and how to validate it or it is generated from sqlserver.
please tell me how it is generated from sqlserver or asp.net application

please help me
thank you.
Posted

Dear Friend,

you can generate a random number in .net for the same:-
Random rnd = new Random();
long number = Convert.ToInt64(rnd.Next(1,10000));


The upper range can be increased according as to how big random number you want to generate.

Else you can also generate a unique GUID code of 16 digits, which is always unique
Guid g;
// Create and display the value of two GUIDs.
g = Guid.NewGuid();


Refer:-http://msdn.microsoft.com/en-us/library/system.guid.newguid.aspx[^]

Please don't forget to mark this as your answer if it helps you out.
 
Share this answer
 
Use following javascript to generate code of 10 character.
JavaScript
<script language="javascript" type="text/javascript">
        function GetString(txtCode) {
            document.getElementById(txtCode).value = RamdomString(10);
            return false;
        }
        //Random String Generator//
        function RamdomString(intLen) {
            var strRet = "";
            var iCntr = 0;
            var rndNo = 0;
            var arrCharacters = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
            for (iCntr = 0; iCntr < intLen; iCntr++) {
                rndNo = Math.floor((61 - 1 + 1) * Math.random() + 1);
                strRet = strRet + arrCharacters[rndNo];
            }
            return strRet;
        }
    </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900