Skip to main content
February 16, 2023
Solved

can we generate auto generate alphanumeric characters for password ?

  • February 16, 2023
  • 6 replies
  • 0 views

like we get alphanumeric characters we get to reset the password ?

Best answer by ayusha3676

a!localVariables(
  local!array: {
    33 + tointeger(rand(5) * (47 - 33)), /* For special chars*/
    48 + tointeger(rand(8) * (57 - 48)), /* For integer*/
    65 + tointeger(rand(10) * (90 - 65)) /* For alphabets*/
  },
  local!oldIndex: enumerate(length(local!array)) + 1,
  local!newIndex: union(
    1 + tointeger(
      rand(length(local!array)) * (length(local!array) - 1)
    ),
    tointeger({})
  ),
  local!diffindex: difference(local!oldIndex, local!newIndex),
  local!finalIndex: append(local!newIndex, local!diffindex),
  joinarray(
    a!forEach(
      items: local!finalIndex,
      expression: char(index(local!array, fv!item, {}))
    ),
    ""
  )
)

Here, 5, 8, and 10 represent the length of the characters written next to them!

6 replies

ayusha3676
February 16, 2023

a!localVariables(
  local!array: {
    33 + tointeger(rand(5) * (47 - 33)), /* For special chars*/
    48 + tointeger(rand(8) * (57 - 48)), /* For integer*/
    65 + tointeger(rand(10) * (90 - 65)) /* For alphabets*/
  },
  local!oldIndex: enumerate(length(local!array)) + 1,
  local!newIndex: union(
    1 + tointeger(
      rand(length(local!array)) * (length(local!array) - 1)
    ),
    tointeger({})
  ),
  local!diffindex: difference(local!oldIndex, local!newIndex),
  local!finalIndex: append(local!newIndex, local!diffindex),
  joinarray(
    a!forEach(
      items: local!finalIndex,
      expression: char(index(local!array, fv!item, {}))
    ),
    ""
  )
)

Here, 5, 8, and 10 represent the length of the characters written next to them!

February 16, 2023

Thank you @AyushAgrawal

sunilc6392
February 16, 2023

concat(
  char(
    a!forEach(
      items: enumerate(10),
      expression: if(
        contains({ 1, 4, 7, 10 }, fv!index),
        34 + tointeger(rand() * (47 - 33)),
        contains({ 2, 5, 8 }, fv!index),
        48 + tointeger(rand() * (57 - 48)),
        68 + tointeger(rand() * (90 - 65))
      )
    )
  )
)


You can also use this for generate random string with special characters, numbers, and alphabets for password.

vaibhavs2541
February 16, 2023

concat(
  char(
    a!forEach(
      items: enumerate(15),
      expression: if(
        fv!index <= 4,
        34 + tointeger(rand() * (38 - 34)),
        fv!index <= 9,
        48 + tointeger(rand() * (57 - 48)),
        68 + tointeger(rand() * (90 - 68))
      )
    )
  )
)

It generates a Text of special characters, alphabets and numbers which is random every time you test this code

jalajv3083
February 16, 2023

joinarray(
  char(
    a!forEach(
      items: enumerate(15),
      expression: a!localVariables(
        local!charSet: {
          33 + tointeger(rand() * (90 - 33)),
          97 + tointeger(rand() * (122 - 97)),
        },
        local!charSet[1 + tointeger(rand() * (2 - 1))]
      )
    )
  )
)

pushpenders6738
February 16, 2023

/*generate alphaNumeric password*/
a!localVariables(
  local!special: (33 + tointeger(rand() * (47 - 33))),
  local!integer: (48 + tointeger(rand() * (57 - 48))),
  local!alphabet: (65 + tointeger(rand() * (90 - 65))),
  {
    joinarray(
      char(
        a!forEach(
          items: enumerate(8) + 1,
          expression: choose(
            fv!item,
            local!special,
            local!alphabet,
            local!integer,
            local!alphabet,
            local!alphabet,
            local!integer,
            local!special,
            local!integer,
          )
        )
      )
    )
  }
)