由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 这段代码可以破解密码攻击 (转载)
相关主题
请教 cross two website Authentication 问题Node.js 并发模型相关:closure 中 access mutable variable
OAuth的scope有什么用?尼玛 callback 真是反人类
jwt token 作认证的问题Help!! variable scope ????
一个C语言的面试题,有点乱,麻烦看一下question about const reference
请问这个C++程序有什么问题吗[合集] static const代替define的performance tradeoff在哪里?
web services的安全性问题。const_cast问题
请教C++ call-by-ref & call-by-val的问题请教C数组定义问题
同步编程真郁闷function declaration
相关话题的讨论汇总
话题: token话题: err话题: client话题: callback话题: const
进入Programming版参与讨论
1 (共1页)
r****m
发帖数: 1
1
【 以下文字转载自 Military 讨论区 】
发信人: reklam (ciel), 信区: Military
标 题: 这段代码可以破解密码攻击
发信站: BBS 未名空间站 (Tue Feb 9 14:15:38 2021, 美东)
从google sheet读取资料的代码示范
把试你们代码的可疑的人的名单放到一个公用的google sheet里
然后你的脚本就可以读取这个名单进行操作
这个名单是小将名单还是老将名单,你们自己决定
const fs = require('fs');
const readline = require('readline');
const {google} = require('googleapis');
// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = 'token.json';
// Load client secrets from a local file.
fs.readFile('credentials.json', (err, content) => {
if (err) return console.log('Error loading client secret file:', err);
// Authorize a client with credentials, then call the Google Sheets API.
authorize(JSON.parse(content), listMajors);
});
/**
* Create an OAuth2 client with the given credentials, and then execute the
* given callback function.
* @param {Object} credentials The authorization client credentials.
* @param {function} callback The callback to call with the authorized
client.
*/
function authorize(credentials, callback) {
const {client_secret, client_id, redirect_uris} = credentials.installed;
const oAuth2Client = new google.auth.OAuth2(
client_id, client_secret, redirect_uris[0]);
// Check if we have previously stored a token.
fs.readFile(TOKEN_PATH, (err, token) => {
if (err) return getNewToken(oAuth2Client, callback);
oAuth2Client.setCredentials(JSON.parse(token));
callback(oAuth2Client);
});
}
/**
* Get and store new token after prompting for user authorization, and then
* execute the given callback with the authorized OAuth2 client.
* @param {google.auth.OAuth2} oAuth2Client The OAuth2 client to get token
for.
* @param {getEventsCallback} callback The callback for the authorized
client.
*/
function getNewToken(oAuth2Client, callback) {
const authUrl = oAuth2Client.generateAuthUrl({
access_type: 'offline',
scope: SCOPES,
});
console.log('Authorize this app by visiting this url:', authUrl);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question('Enter the code from that page here: ', (code) => {
rl.close();
oAuth2Client.getToken(code, (err, token) => {
if (err) return console.error('Error while trying to retrieve access
token', err);
oAuth2Client.setCredentials(token);
// Store the token to disk for later program executions
fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
if (err) return console.error(err);
console.log('Token stored to', TOKEN_PATH);
});
callback(oAuth2Client);
});
});
}
/**
* Prints the names and majors of students in a sample spreadsheet:
* @see https://docs.google.com/spreadsheets/d/
1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
* @param {google.auth.OAuth2} auth The authenticated Google OAuth client.
*/
function listMajors(auth) {
const sheets = google.sheets({version: 'v4', auth});
sheets.spreadsheets.values.get({
spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms',
range: 'Class Data!A2:E',
}, (err, res) => {
if (err) return console.log('The API returned an error: ' + err);
const rows = res.data.values;
if (rows.length) {
console.log('Name, Major:');
// Print columns A and E, which correspond to indices 0 and 4.
rows.map((row) => {
console.log(`${row[0]}, ${row[4]}`);
});
} else {
console.log('No data found.');
}
});
}
1 (共1页)
进入Programming版参与讨论
相关主题
python的scope机制 非常垃圾请问这个C++程序有什么问题吗
socket re-connection problemweb services的安全性问题。
a question of perl请教C++ call-by-ref & call-by-val的问题
python gc question同步编程真郁闷
请教 cross two website Authentication 问题Node.js 并发模型相关:closure 中 access mutable variable
OAuth的scope有什么用?尼玛 callback 真是反人类
jwt token 作认证的问题Help!! variable scope ????
一个C语言的面试题,有点乱,麻烦看一下question about const reference
相关话题的讨论汇总
话题: token话题: err话题: client话题: callback话题: const