0

I want to make a credit card generator that generates credit cards in the format (number|exp.month|exp.year|cvv) and the credit card number follows the luhn algorithm. The user inputs a BIN(Bank Identification Number) starting from which, I generate a sixteen digit credit card using python. I store all the credit cards in a python variable output but when I try to display it on the html page using jinja2 function {{ output }}, it does not show it on the html page.

I am pretty sure that all the html code and math and loop part of python code is correct.

When I try using

def function1:
   return (output)

It shows me no error and gives shows the desired output. But I want this in the HTML file itself and not to load on a new separate page.

Index.html:

<!DOCTYPE html>
<html>
    <head>
        <title>
            Home
        </title>
    </head>
    <body>
        <h1>
            Fire CC Generator
        </h1>

        <form action="{{ url_for("function1") }}" method="post">
            <label for="Bin">B.I.N.</label>
            <input type="text" name="Bin" placeholder="Enter BIN"><br>
            <input type="text" name="quantity" placeholder="Enter Quantity"><br>
            <button type="button" value="Submit">
        </form>
        <p>
            Output: {{output}}
        </p>
    </body>
</html>

index.py:

import random
from flask import Flask, render_template, request, url_for
app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def function1():
   if request.method == 'POST':

      # getting input with name = Bin in HTML form

      Bin = request.form.get('Bin')

      # getting input with name = lname in HTML form

      quantity = int(request.form.get('quantity'))
      x = 0
      ccnum = 0
      good = 16 - len(Bin)

      output = ''
      exp_month_list = [
         '01',
         '02',
         '03',
         '04',
         '05',
         '06',
         '07',
         '08',
         '09',
         '10',
         '11',
         '12',
         ]

      while x != quantity:
         r = str(random.randint(pow(10, good - 1), pow(10, good)- 1))
         iccnum = Bin + r

         # Luhn Algorithm Begins

         def luhn_checksum(card_number):

            def digits_of(n):
               return [int(d) for d in str(n)]
            digits = digits_of(card_number)
            odd_digits = digits[-1::-2]
            even_digits = digits[-2::-2]
            checksum = 0
            checksum += sum(odd_digits)
            for d in even_digits:
               checksum += sum(digits_of(d * 2))
            return checksum % 10

         # Luhn Algorithm Ends

         if luhn_checksum(int(iccnum)) == 0:
            ccnum = iccnum
            ccnum = str(ccnum)
            exp_month = random.choice(exp_month_list)
            exp_year = str(random.randint(2022, 2026))
            cvv = str(random.randint(100, 999))
            CC = str(ccnum + '|' + exp_month + '|' + exp_year + '|'+ cvv + '\n')
            output += CC
            x += 1
         else:
            x = x
         return render_template('index.html', output=output)
   return render_template('index.html')
if __name__ == '__main__':
    app.run()

GitHub Repository link: https://github.com/FieryKing01/Python-CC-generator

1
  • I left jinga for good. Now I don't even know how to spell it. Jinga is waste of time. I should have simply learned JS instead. Commented Jan 28, 2022 at 8:19

1 Answer 1

1

It looks to me like the issue here is that you've got to 'feed' the output variable to render_template, so, like:

return render_template('index.html', output = output)
Sign up to request clarification or add additional context in comments.

6 Comments

I have made the required changes in the code but still getting the same error. @jmaloney13
@FieryKing - it looks like, in editing, you moved 'return render_template('index.html')' to the top of your function, before the 'if' statement. I think that might be the problem.
I moved it to where it was before. But still same problem @jmaloney13
I would try moving it to where it was before and see if that works. But, I'll be honest, I don't understand everything you're doing here. Where it is now, though, function1() will only ever return render_template('index.html') without the 'output'. It'll never get to any of the stuff in the 'if' statement because it'll just stop after it gets to the first 'return'.
I don't understand. if possible, could you please make the required changes and share it with me on [email protected] so that I can understand better.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.