ChatGPT is an artificial intelligence network that interacts in a chat-like way. It looks like another "chatbot" by name, but it is actually far beyond the scope of chat. When it is asked to write some code, the results are equally shocking. It can write some unexpected coherent code that is very inspiring to developers.
Start asking it to write a hash (HASH) password function using JavaScript. To be specific, write a JavaScript function that accepts string input of the password and outputs a hash (HASH) password.
function hashPassword(password) { return ("sha256").update(password).digest("hex"); }
Then gradually increase the difficulty of coding to achieve some more in line with the needs of project development, so enter:
Write an Express routing handler that contains the username and password in the request body, hash the password, find existing users in the MySQL database and check whether the hashed password matches.
const express = require("express"); const bcrypt = require("bcrypt"); const mysql = require("mysql"); // Create MySQL database connectionconst db = ({ host: "localhost", user: "root", password: "", database: "mydb", }); // Connect to the database((err) => { if (err) { throw err; } ("MySQL connected..."); }); // Create an express appconst app = express(); //Routing handler("/login", (req, res) => { // get username and password from request body const { username, password } = ; // HASH password const hashedPassword = (password, 10); // Find user name in the database let sql = `SELECT * FROM users WHERE username = '${username}'`; let query = (sql, (err, result) => { if (err) throw err; // Check if the password matches if ((result[0].password, hashedPassword)) { ("Login successful!"); } else { ("Incorrect username or password"); } }); });
This JavaScript code is basically fine and can be copied directly into the project for debugging. Next, try another language:
Write a code for a linked list structure in C language, which has the function of adding, deleting and finding nodes in the linked list according to the "identification" attribute.
#include <> #include <> // Structure for a node in the linked list typedef struct Node { int identity; // Property of the node struct Node *next; // Pointer to the next node } Node; // Function to add a node to the linked list void addNode(Node **head, int identity) { // Create a new node Node *newNode = (Node*)malloc(sizeof(Node)); // Set the identity of the new node newNode->identity = identity; // Set the next pointer of the new node to point to the head newNode->next = *head; // Set the head to point to the new node *head = newNode; } // Function to delete a node from the linked list void deleteNode(Node **head, int identity) { // Create a temporary node to traverse the linked list Node *temp = *head; // Check if the head is the node to be deleted if (temp != NULL && temp->identity == identity) { // Set the head to point to the next node *head = temp->next; // Free the memory allocated for the node free(temp); return; } // Traverse the linked list to find the node to be deleted while (temp != NULL && temp->identity != identity) { // Set the previous node to the current node Node *prev = temp; // Set the current node to the next node temp = temp->next; } // Check if the node was found if (temp == NULL) return; // Set the previous node to point to the next node prev->next = temp->next; // Free the memory allocated for the node free(temp); } // Function to find a node in the linked list Node* findNode(Node *head, int identity) { // Create a temporary node to traverse the linked list Node *temp = head; // Traverse the linked list to find the node while (temp != NULL) { // Check if the current node has the given identity if (temp->identity == identity) { return temp; } // Set the current node to the next node temp = temp->next; } // Return NULL if the node was not found return NULL; } int main() { // Create a head node for the linked list Node *head = NULL; // Add some nodes to the linked list addNode(&head, 1); addNode(&head, 2); addNode(&head, 3); // Find a node in the linked list Node *node = findNode(head, 2); // Print the identity of the node printf("Node with identity 2: %d\n", node->identity); // Delete a node from the linked list deleteNode(&head, 2); // Find the deleted node in the linked list node = findNode(head, 2); // Check if the node was deleted if (node == NULL) { printf("Node with identity 2 was deleted\n"); } return 0; }
So I seem to be beginning to worry that future programmers will definitely be stronger than humans in AI's machine learning capabilities. Even if a programmer has a valuable career of 20 years, it is assumed that this programmer is very diligent and studious in his career, but AI should be able to collect the experience of all programmers around the world through learning! The human brain cannot compare with the computing power of well-trained AI models on extremely large data sets.Is it possible for programmers to eliminate their profession through AI in the future?
Summarize
This is the end of this article about using OpenAI ChatGPT for coding and trying experience. For more related OpenAI ChatGPT encoding content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!