codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.59k stars 1.09k forks source link

WiFi Payload Won't Generate Correctly #461

Closed futureflash01 closed 5 months ago

futureflash01 commented 1 year ago

Type of issue

Bug

Expected Behavior

WiFi Payload should generate a valid QR Code for ANY kind of string.

Current Behavior

If you explicitly provide a string within the "" parameters, the QR Code will generate correctly. However, instead of typing a hard coded SSID and password, whenever I use another variable that has a string, for example "textBox1.Text", it returns an empty string rather than using whatever text is inside the TextBox. In other words, typing in: PayloadGenerator.WiFi wifiPayload = new PayloadGenerator.WiFi("MyWiFi-SSID", "MyWiFi-Pass", PayloadGenerator.WiFi.Authentication.WPA); works fine. but typing in: PayloadGenerator.WiFi wifiPayload = new PayloadGenerator.WiFi(ssidTextBox.Text, passwordTextBox.Text, PayloadGenerator.WiFi.Authentication.WPA); does NOT work! And also, I even tried using 'ssidTextBox.Text.ToString()' and still doesn't work. I'm not sure why. A string is a string regardless.

Possible Solution (optional)

Make the PayloadGenerator.WiFi class accept ANY kind of string, rather than a hard coded value

Steps to Reproduce (for bugs)

  1. Make a TextBox for a user provided SSID or password
  2. Use the value of that textbox in a PayloadGenerator.WiFi class
  3. QR Code results in generating an empty SSID and an empty password, rather than what the user inputted

Your Environment

Shane32 commented 5 months ago

Please compare the result of wifiPayload.ToString() with the two different methods and see if there is a difference in the generated text.

codebude commented 5 months ago

Hi @futureflash01 ,

A string is a string regardless.

Yes, and that's also true for QRCoder. The only reason I can think of, why the QRCode generated with text from your textBox is empty, is that your textBox isn't filled/used properly. My guess is that the problem is not QRCoder but anywhere else in your code. To proof this, please change this line:

PayloadGenerator.WiFi wifiPayload = new PayloadGenerator.WiFi(ssidTextBox.Text, passwordTextBox.Text, PayloadGenerator.WiFi.Authentication.WPA);

to:

string input = ssidTextBox.Text;
PayloadGenerator.WiFi wifiPayload = new PayloadGenerator.WiFi(input, passwordTextBox.Text, PayloadGenerator.WiFi.Authentication.WPA);

If you set a breakpoint at the second line, you should see that also the input-variable is already empty.