Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parte express
- const express = require('express')
- const app = express()
- const mysql = require('mysql')
- const connection = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- database: 'auto'
- })
- const basicAuth = require('express-basic-auth')
- connection.connect((error) => {
- if (error) throw error
- console.log('Avviato')
- })
- app.use(basicAuth({
- authorizer: asyncAuthorizer,
- authorizeAsync: true,
- challenge: true
- }))
- function asyncAuthorizer(username, password, callback) {
- connection.query('SELECT 1 FROM Users WHERE Username = ? AND Password = ?', [username, password], (error, results) => {
- if (error) throw error
- if (results.length > 0)
- callback(null, true)
- else
- callback(null, false)
- })
- }
- app.get('/', (request, response) => {
- response.send('OKK')
- })
- app.listen(9090, (error) => {
- if (error) throw error
- console.log('Avviato su porta 9090')
- })
- // Parte C#
- private ICredentials credentials = new NetworkCredential(); // Variabile globale della classe
- // Quando creo il WebClient setto le credenziali, es
- using (var client = new WebClient())
- {
- client.Credentials = credentials;
- // C'รจ un bottone per settare le credenziali:
- private void btnSet_Click(object sender, EventArgs e)
- {
- this.credentials = new NetworkCredential(txtUsername.Text, txtPassword.Text);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement