code: def register():
      """Register a new user.
  
      Validates that the username is not already taken. Hashes the
      password for security.
      """
      if request.method == "POST":
          username = request.form["username"]
          password = request.form["password"]
          db = get_db()
          error = None
  
          if not username:
              error = "Username is required."
          elif not password:
              error = "Password is required."
  
          if error is None:
              try:
                  db.execute(
                      "INSERT INTO user (username, password) VALUES (?, ?)",
                      (username, generate_password_hash(password)),
                  )
                  db.commit()
              except db.IntegrityError:
                  # The username was already taken, which caused the
                  # commit to fail. Show a validation error.
                  error = f"User {username} is already registered."
              else:
                  # Success, go to the login page.
                  return redirect(url_for("auth.login"))
  
          flash(error)
  
      return render_template("auth/register.html")
  
file_path: flask/examples/tutorial/flaskr/auth.py
imports: import functools
  from flask import Blueprint
  from flask import flash
  from flask import g
  from flask import redirect
  from flask import render_template
  from flask import request
  from flask import session
  from flask import url_for
  from werkzeug.security import check_password_hash
  from werkzeug.security import generate_password_hash
  from .db import get_db
label_desc: Use image node_id 3 for calling a global function with example usage: register() and returns: render_template, redirect