locked
How to generate an ID for each user accessing my web system? RRS feed

  • Question

  • User1554093342 posted

    Hello everyone, I'm developing a system that will be running on TVs, or through the Smart TV browser, or Android TVBOX or chromecast.

    I would like to know how I could generate an ID for each device, because I need to register on my system if TV 123 is enabled to open my system ..

    It will basically be a corporate display panel.

    I need a combination of client data that generates an ID.

    Suggestions?

    Tuesday, October 10, 2017 11:17 PM

Answers

  • User347430248 posted

    Hi giovannidebo...,

    you had mentioned that,"I would like to know how I could generate an ID for each device, because I need to register on my system if TV 123 is enabled to open my system .."

    I can see 2 things in above sentence.

    first you said you want to generate an id for each device.

    second is you want to register in your system if particular TV is enabled to access your system.

    if you want to generate an id then you can try to generate random number or alphanumeric value and try to save it to cookies on client side.

    var id = Guid.NewGuid().ToString()

    or

    private string GetUniqueKey()
    {
    int maxSize  = 8 ;
    int minSize = 5 ;
    char[] chars = new char[62];
    string a;
    a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    chars = a.ToCharArray();
    int size  = maxSize ;
    byte[] data = new byte[1];
    RNGCryptoServiceProvider  crypto = new RNGCryptoServiceProvider();
    crypto.GetNonZeroBytes(data) ;
    size =  maxSize ;
    data = new byte[size];
    crypto.GetNonZeroBytes(data);
    StringBuilder result = new StringBuilder(size) ;
    foreach(byte b in data )
    { result.Append(chars[__b % (chars.Length - )>); }
     <span class="code-keyword">return result.ToString();
    }

    Reference:

    Generating Unique Keys in .Net

    or

    protected void GenerateOTP(object sender, EventArgs e)
    {
        string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
        string numbers = "1234567890";
     
        string characters = numbers;
        if (rbType.SelectedItem.Value == "1")
        {
            characters += alphabets + small_alphabets + numbers;
        }
        int length = int.Parse(ddlLength.SelectedItem.Value);
        string otp = string.Empty;
        for (int i = 0; i < length; i++)
        {
            string character = string.Empty;
            do
            {
                int index = new Random().Next(0, characters.Length);
                character = characters.ToCharArray()[index].ToString();
            } while (otp.IndexOf(character) != -1);
            otp += character;
        }
        lblOTP.Text = otp;
    }

    Reference:

    Generate Unique Random Strings containing Letters and Numbers (AlphaNumeric) and Numbers (Numeric) in ASP.Net using C# and VB.Net

    then you can try to access cookie value to identify the particular TV.

    but in this case you need to know that which TV has which ID.

    other thing you had mentioned that you need to register on your system if TV 123 is enabled to open my system .. 

    here, I think you need to access Mac Address or Android ID or IMEI No for accurate result.

    I try to find the example code to access it using Asp.net but did not get any useful example for this.

    all the examples I got was using the Java. so it cannot help you.

    other then that you can try to find some Api which lets you to access Android device information may solve your issue.

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 11, 2017 1:47 AM

All replies

  • User347430248 posted

    Hi giovannidebo...,

    you had mentioned that,"I would like to know how I could generate an ID for each device, because I need to register on my system if TV 123 is enabled to open my system .."

    I can see 2 things in above sentence.

    first you said you want to generate an id for each device.

    second is you want to register in your system if particular TV is enabled to access your system.

    if you want to generate an id then you can try to generate random number or alphanumeric value and try to save it to cookies on client side.

    var id = Guid.NewGuid().ToString()

    or

    private string GetUniqueKey()
    {
    int maxSize  = 8 ;
    int minSize = 5 ;
    char[] chars = new char[62];
    string a;
    a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    chars = a.ToCharArray();
    int size  = maxSize ;
    byte[] data = new byte[1];
    RNGCryptoServiceProvider  crypto = new RNGCryptoServiceProvider();
    crypto.GetNonZeroBytes(data) ;
    size =  maxSize ;
    data = new byte[size];
    crypto.GetNonZeroBytes(data);
    StringBuilder result = new StringBuilder(size) ;
    foreach(byte b in data )
    { result.Append(chars[__b % (chars.Length - )>); }
     <span class="code-keyword">return result.ToString();
    }

    Reference:

    Generating Unique Keys in .Net

    or

    protected void GenerateOTP(object sender, EventArgs e)
    {
        string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
        string numbers = "1234567890";
     
        string characters = numbers;
        if (rbType.SelectedItem.Value == "1")
        {
            characters += alphabets + small_alphabets + numbers;
        }
        int length = int.Parse(ddlLength.SelectedItem.Value);
        string otp = string.Empty;
        for (int i = 0; i < length; i++)
        {
            string character = string.Empty;
            do
            {
                int index = new Random().Next(0, characters.Length);
                character = characters.ToCharArray()[index].ToString();
            } while (otp.IndexOf(character) != -1);
            otp += character;
        }
        lblOTP.Text = otp;
    }

    Reference:

    Generate Unique Random Strings containing Letters and Numbers (AlphaNumeric) and Numbers (Numeric) in ASP.Net using C# and VB.Net

    then you can try to access cookie value to identify the particular TV.

    but in this case you need to know that which TV has which ID.

    other thing you had mentioned that you need to register on your system if TV 123 is enabled to open my system .. 

    here, I think you need to access Mac Address or Android ID or IMEI No for accurate result.

    I try to find the example code to access it using Asp.net but did not get any useful example for this.

    all the examples I got was using the Java. so it cannot help you.

    other then that you can try to find some Api which lets you to access Android device information may solve your issue.

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 11, 2017 1:47 AM
  • User379720387 posted

    I am sure these devices already have a unique Id, probably in the form of a MAC address or something along those lines.

    Thursday, January 16, 2020 12:02 PM