當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript crypto-js.SHA256函數代碼示例

本文整理匯總了TypeScript中crypto-js.SHA256函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript SHA256函數的具體用法?TypeScript SHA256怎麽用?TypeScript SHA256使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了SHA256函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: addNewMember

 /**
  * @description
  * <p>This method send a request to the backend of MaaS with the purpose
  * to add one member to one company.</p>
  * @param company_id {string} ID of the company
  * @param token {string} Token of the user
  * @param memberData {IAddMemberUser} New member data
  * @returns {Promise<T>|Promise} The result or the error
  */
 public addNewMember(
     company_id : string,
     token : string,
     memberData : IAddMemberUser
 ) : Promise<Object> {
         let encript1 : string = crypto.SHA256(
             memberData.password,
             "BugBusterSwe"
         ).toString();
         memberData.password = crypto.SHA256(encript1, "MaaS").toString();
         return new Promise(
             function(resolve : (jsonObject : IAddMemberResponse) => void,
                     reject : (error : ActionError) => void) : void {
             request
                 .post
                 ("/api/companies/" + company_id + "/users")
                 .set("Accept", "application/json")
                 .set("x-access-token", token)
                 .send(memberData)
                 .end(function(error : Object, res : Response) : void {
                     if (error) {
                         let actionError : ActionError = res.body;
                         reject(actionError);
                     } else {
                         let addCompanyResponse : IAddMemberResponse =
                             res.body;
                         resolve(addCompanyResponse);
                     }
             });
         });
 }
開發者ID:BugBusterSWE,項目名稱:MaaS,代碼行數:40,代碼來源:companyAPIs.ts

示例2: superAdminCreation

 /**
  * @description
  * <p>This method send a request of super admin registration
  * to the backend of MaaS.</p>
  * @param data {ISupeAdminCreation}
  * @param token {string}
  * @returns {Promise<Object>|Promise} The result or the error
  */
 public superAdminCreation(
   data : ISupeAdminCreation,
   token : string
  ) : Promise<Object> {
     let encript1 : string = crypto.SHA256(
         data.password,
         "BugBusterSwe"
       ).toString();
     data.password = crypto.SHA256(encript1, "MaaS").toString();
     return new Promise(
         function(
             resolve : (jsonObject : ISuperAdminCreationResponse) => void,
             reject : (error : ActionError) => void) : void {
         request
             .post
             ("/api/admin/superadmins")
             .set("Accept", "application/json")
             .set("x-access-token", token)
             .send(data)
             .end(function(error : Object, res : Response) : void {
                 if (error) {
                     let actionError : ActionError = res.body;
                     reject(actionError);
                 } else {
                     let userRegistrationResponse :
                         ISuperAdminCreationResponse = res.body;
                     resolve(userRegistrationResponse);
                 }
         });
     });
 }
開發者ID:BugBusterSWE,項目名稱:MaaS,代碼行數:39,代碼來源:userAPIs.ts

示例3: createUser

    /**
     * @api {post} api/companies/:company_id/users Create a new User
     * @apiVersion 1.0.0
     * @apiName createUser
     * @apiGroup User
     * @apiPermission OWNER
     *
     * @apiDescription Use this request to insert a new user in a stated
     * company.
     *
     * @apiParam {String} company_id The Company's ID.
     * @apiParam {String} user_id The ID of the logged user.
     *
     * @apiExample Example usage:
     * curl  \
     *  -H "Accept: application/json" \
     *  -H "x-access-token: {authToken}" \
     *  -X POST \
     *  -d '{"email": "prova@try.it,  }' \
     *  http://maas.com/api/companies/5741/users
     *
     * @apiSuccess {string} _id The User's _id.
     * @apiSuccess {string} email the email address of the user.
     * @apiSuccess {string} level the level of the user.
     * 
     * @apiError NoAccessRight Only authenticated Owners can access the data.
     * @apiError CannotCreateTheUser It was impossible to create the user.
     * @apiError ErrorSendingEmail Can't send the email
     * 
     * @apiErrorExample Response (example):
     *     HTTP/1.1 400
     *     {
     *       "code"  : "ECU-001",
     *       "error" : "Cannot create the user"
     *     }
     */
    /**
     * @description Create a new user for a specific company.
     * @param request The express request.
     * <a href="http://expressjs.com/en/api.html#req">See</a> the official
     * documentation for more details.
     * @param response The express response object.
     * <a href="http://expressjs.com/en/api.html#res">See</a> the official
     * documentation for more details.
     */
    private createUser(request : express.Request,
                       response : express.Response) : void {
        let userData : UserDocument = request.body;
        userData.company = request.params.company_id;
        let initial_pass : string = crypto.randomBytes(20).toString("base64");
        let mailOptions : MailOptions = {
            from: "service@maas.com",
            to: userData.email,
            subject: "MaaS registration",
            text: "Hello and welcome in MaaS! \n" +
            "You can start using our service from now!\n\n" +
            "Below you can find your credentials: \n\n" +
            "Email: " + userData.email + "\n" +
            "Password: " + initial_pass + "\n\n" +
            "Best regards, \n" +
            "The MaaS team",
            html: "",
        };

        let encript1 : string = cryptoFE.SHA256(
            initial_pass, "BugBusterSwe").toString();
        let encryptedPassword : string = cryptoFE.SHA256(
            encript1, "MaaS").toString();

        userData.password = encryptedPassword;

        mailSender(mailOptions, function (error : Object) : void {
            if (!error) {
                user
                    .create(userData)
                    .then(function (data : UserDocument) : void {
                        response
                            .status(200)
                            .json(data);
                    }, function () : void {
                        response
                            .status(400)
                            .json({
                                code: "ECU-001",
                                message: "Cannot create the user."
                            });
                    });
            } else {
                response
                    .status(400)
                    .json({
                        code: "ECM-001",
                        message: "Error sending Email."
                    });
            }
        });
    }
開發者ID:BugBusterSWE,項目名稱:MaaS,代碼行數:97,代碼來源:userRouter.ts

示例4: function

RouterFacade.get("/setup", function (request : express.Request,
                                    response : express.Response) : void {
    let encript1 : string = crypto.SHA256(
        "123456ciao", "BugBusterSwe").toString();
    let encryptedPassword : string = crypto.SHA256(
        encript1, "MaaS").toString();
    user.addSuperAdmin({
        email: "bug@prova.it",
        password: encryptedPassword
    }).then(function (data : Object) : void {
        response.json(data);
    }, function (error : Object) : void {
        response.json(error);
    });
});
開發者ID:BugBusterSWE,項目名稱:MaaS,代碼行數:15,代碼來源:routerFacade.ts

示例5: addCompany

 /**
  * @description
  * <p>This method send a request to the backend of MaaS with the purpose
  * to add one company.</p>
  * @param user {IAddCompanyUser} Data of the owner of the company
  * @param company {ICompanyName} Company data
  * @param token {string} Token of the user
  * @returns {Promise<T>|Promise} the result or the error
  */
 public addCompany(user : IAddCompanyUser,
                   company : ICompanyName) : Promise<Object> {
     let encript1 : string = crypto.SHA256(
         user.password, "BugBusterSwe").toString();
     user.password = crypto.SHA256(encript1, "MaaS").toString();
     return new Promise(
         function(resolve : (jsonObject : IAddCompanyResponse ) => void,
                  reject : (error : ActionError) => void) : void {
         request
             .post("/api/companies")
             .send({user, company})
             .end(function(error : Object, res : Response) : void {
                 if (error) {
                     let actionError : ActionError = res.body;
                     reject(actionError);
                 } else {
                     let addCompanyResponse : IAddCompanyResponse = res.body;
                     resolve(addCompanyResponse);
                 }
             });
     })
 }
開發者ID:BugBusterSWE,項目名稱:MaaS,代碼行數:31,代碼來源:companyAPIs.ts

示例6: loginLogbook

 public loginLogbook(emailAddress: string, password: string) : Promise<JsonWebTokenModel> {
     let body = {
         emailAddress: emailAddress,
         passwordSHA256Hash: crypto.SHA256(password).toString(crypto.enc.Base64),
     };
     
     return this.httpClient
         .createRequest("Authentication/Login/Logbook")
         .asPost()
         .withContent(body)
         .send()
         .then(response => response.content)
         .catch(response => Promise.reject(response.content.message));
 }
開發者ID:LeagueLogbook,項目名稱:LogbookWebsite,代碼行數:14,代碼來源:authentication-api.ts

示例7: updateUserPassword

    /**
     * @description
     * <p>This method send a request of update of password
     * to the backend of MaaS.</p>
     * @param data {IUpdateUserPassword}
     * @returns {Promise<T>|Promise} The result or the error
     */
    public updateUserPassword(data : IUpdateUserPassword) : Promise<Object> {
        let encript1NP : string = crypto.SHA256(
            data.newPassword, "BugBusterSwe").toString();
        let encryptedPasswordNP : string = crypto.SHA256(
            encript1NP, "MaaS").toString();
        let encript1OP : string = crypto.SHA256(
            data.password, "BugBusterSwe").toString();
        let encryptedPasswordOP : string = crypto.SHA256(
            encript1OP, "MaaS").toString();
        return new Promise(
            function(
                resolve : (jsonObject : IUpdate) => void,
                reject : (error : ActionError) => void) : void {
                request
                    .put("/api/companies/" + data.company_id + "/users/"
                        + data._id + "/credentials")
                    .send(
                        {   username: data.username,
                            password : encryptedPasswordOP,
                            newUsername: data.newUsername,
                            newPassword: encryptedPasswordNP
                        })
                    .set("Accept", "application/json")
                    .set("x-access-token", data.token)
                    .end(function(error : Object, res : Response) : void {
                        if (error) {
                            let actionError : ActionError = res.body;
                            reject(actionError);
                        } else {

                            let updateUserPasswordResponse :
                                IUpdate = res.body;
                            resolve(updateUserPasswordResponse);
                        }
                    });
            });
    }
開發者ID:BugBusterSWE,項目名稱:MaaS,代碼行數:44,代碼來源:userAPIs.ts

示例8: login

 /**
  * @description This method send a request of login to the backend of MaaS.
  * @param email {string} Email of the user
  * @param password {string} Password of the user
  * @returns {Promise<T>|Promise} The result or the error
  */
 public login(email : string, password : string) : Promise<Object> {
     let encript1 : string = crypto.SHA256(
         password, "BugBusterSwe").toString();
     let encryptedPassword : string = crypto.SHA256(
         encript1, "MaaS").toString();
     return new Promise(
         function(
             resolve : (jsonObj : ILoginResponse) => void,
             reject : (err : ActionError) => void) : void {
             request.post("/api/login")
             .send({email : email, password : encryptedPassword,
                 grant_type : "password"})
             .set("Content-Type", "application/json")
             .end(function(error : Object, res : Response) : void{
                 if (error) {
                     let actionError : ActionError = res.body;
                     reject(actionError);
                 } else {
                     let loginResponse : ILoginResponse = res.body;
                     resolve(loginResponse);
                 }
             });
     });
 }
開發者ID:BugBusterSWE,項目名稱:MaaS,代碼行數:30,代碼來源:sessionAPIs.ts

示例9: register

    public register(emailAddress: string, password: string, language: string) : Promise<void> {
        let body = {
            emailAddress: emailAddress,
            passwordSHA256Hash: crypto.SHA256(password).toString(crypto.enc.Base64),
            preferredLanguage: language,
        };

        return this.httpClient
            .createRequest("Authentication/Register")
            .asPost()
            .withContent(body)
            .send()
            .then(response => null)
            .catch(response => Promise.reject(response.content.message));
    }
開發者ID:LeagueLogbook,項目名稱:LogbookWebsite,代碼行數:15,代碼來源:authentication-api.ts

示例10: createToken

    private async createToken(user: MoAdmins): Promise<string> {
        const token = SHA256(`${user.id} ${user.login} ${Math.random()} ${new Date().toISOString}`).toString();

        // Remove old auth key, just in case it's in DB
        await Logout.cleanAuth(user);

        const usersAuth = new MoUsersAuth();

        usersAuth.timestamp = new Date();
        usersAuth.token = token;
        usersAuth.user = user;

        await getConnection().getRepository(MoUsersAuth).save(usersAuth);

        return token;
    }
開發者ID:Maxtream,項目名稱:themages-cms,代碼行數:16,代碼來源:login.ts


注:本文中的crypto-js.SHA256函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。