Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Random password generator + algorithm

I'm currently developing a CLI password generator and I've been trying to come up with ways of randomizing characters between a defined set of chars. I know the srand(time(NULL)) method, but as far as I know, it's a bit inconsistent and not so safe to generate random passwords.

I also know there is a way of randomizing numbers using the libsodium library for C (according to this topic), but I'm not sure how to use it. Should I install all the dependencies in my project? It is a relatively small project to have such a huge library. Although I plan on expanding it as time goes by, I don't know if it's worth having a huge library and not use most of its functions.

On top of that, are there specific algorithms to generate passwords other than just randomizing characters? Should I also randomize the array within itself following another algorithm for better consistency, like the Fisher Yates Shuffle?

Answer*

Draft saved
Draft discarded
Cancel
12
  • Hello Jonathan! Thank you so much for your response! There are a couple of things I didn't understand though. For example, in your topics 1 and 2, you ask "Is the requirement for a function or a program?", and "should its random numbers be independent of other sequences created by the same program?", how could that be? Commented May 4, 2023 at 16:57
  • Also, this CLI password generator is my final project in CS50, which is still currently under development. You can see it in this repo. I'll be trying to wrap my mind around your reply so I can plug in the concepts you described in your SOQ repository. Commented May 4, 2023 at 17:03
  • If you have a function that will be used repeatedly, the second question (about the independence of random number sequences) becomes important. If you're just writing a program to generate one, or several, random passwords, there is no other random sequence to worry about. If you're doing simulations, you may want to ensure that your random numbers are repeatable. The rand() function has only one seed used by all threads — so independent sequences are not feasible. Commented May 4, 2023 at 23:06
  • The drand48() family of functions provides some which have independent seeds, so you can have different sequences depending on which seed values you use. And the prng48_*() family of functions exploits nrand48() because it takes a user-specified seed. Getting a good, random enough, initial value for the seed is a whole separate bag of worms. Commented May 4, 2023 at 23:09
  • Thank you for your explanation, now I understand it better. I spent the whole day researching the topic and looking at the code you wrote to get a grasp on it. Additionally, I wanted to ask how does drand48() differs from dev/random or dev/urandom? Also, how could I implement the solutions you mentioned in your repository on my project? What libraries would I have to use? Commented May 4, 2023 at 23:24

lang-c

AltStyle によって変換されたページ (->オリジナル) /