Unpredictable Unique Identifier

前端 未结 4 937
情书的邮戳
情书的邮戳 2021-01-03 03:40

For an application I am working on, I need to generate a session token which must have following properties:

  • it should be unique for the application at least,
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 04:35

    How about using what ASP.NET uses to generate unique, unpredictable and secure session ids:

    using System;
    using System.IO;
    using System.Web;
    using System.Web.SessionState;
    
    class Program
    {
        static void Main()
        {
            var request = new HttpRequest("", "http://localhost", "");
            var response = new HttpResponse(TextWriter.Null);
            var context = new HttpContext(request, response);
            var id = new SessionIDManager().CreateSessionID(context);
            Console.WriteLine(id);
        }
    }
    

提交回复
热议问题